QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#775836#9472. Liaoning Ship’s VoyagesurenjamtsWA 1ms3888kbC++204.2kb2024-11-23 16:49:092024-11-23 16:49:09

Judging History

This is the latest submission verdict.

  • [2024-11-23 16:49:09]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3888kb
  • [2024-11-23 16:49:09]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mk make_pair
#define S second
#define F first

struct Point{
   int x, y;
};
Point mult(Point p, int* mat){
    int x = p.x * mat[0] + p.y * mat[2];
    int y = p.x * mat[1] + p.y * mat[3];
    return {x, y};
}

void print(Point p){
   cout << setprecision(18) << "[" << p.x << "," << p.y << "]\n";
}
bool intr(Point p1, Point p2, Point p3, Point p4){
   // print(p1); print(p2); print(p3); print(p4);
    int mat[] = {p2.x - p1.x, p2.y - p1.y, p4.x - p3.x, p4.y - p3.y};
    swap(mat[0], mat[3]);
    mat[1] *= -1;
    mat[2] *= -1;

    p1 = mult(p1, mat); p2 = mult(p2, mat); p3 = mult(p3, mat); p4 = mult(p4, mat);
   // print(p1); print(p2); print(p3); print(p4);
   // cout << "\n";
    if((p1.x >= p3.x || p2.x <= p3.x) && (p2.x >= p3.x || p1.x <= p3.x)) return 0;
    if((p3.y >= p1.y || p4.y <= p1.y) && (p4.y >= p1.y || p3.y <= p1.y)) return 0;
    //cout << "intr\n";
    return 1;
}

int cross(Point p1, Point p2){
     return abs(p1.x * p2.y - p1.y * p2.x);
}
int32_t main(){
     int n;
     while(cin >> n){
          vector<Point> bermud(3);
          for(auto &[x, y] : bermud){
               double f, s;
               cin >> f >> s;
               x = (double(n) - 1.0 - f) * 100;
               y = s * 100;
          }

          string t[n + 5];
          for(int i = 0; i < n; i++) cin >> t[i];
          auto check = [&](int i1, int j1, int i2, int j2){
               //  cout << i1 << " " << j1 << " " << i2 << " " << j2 << endl;
                 if(i2 < 0 || i2 > n - 1) return 0;
                 if(j2 < 0 || j2 > n - 1) return 0;
              //
                 if(t[i2][j2] == '#') return 0;

                 int sum = 0;
                 i1 *= 100; j1 *= 100; i2 *= 100; j2 *= 100;
                 bool paralel = 0;
                 for(int i = 0; i < 3; i++){
                       if(intr(bermud[i], bermud[(i + 1) % 3], {i1, j1}, {i2, j2})) return 0;
                       sum += cross({bermud[i].x - i2, bermud[i].y - j2}, {bermud[(i+1)%3].x - i2, bermud[(i+1)%3].y - j2});
                       if(cross({bermud[i].x - i2, bermud[i].y - j2}, {bermud[(i+1)%3].x - i2, bermud[(i+1)%3].y - j2}) == 0) paralel = 1;
                      // print({bermud[i].x - i2, bermud[i].y - j2});
                      // print({bermud[(i+1)%3].x - i2, bermud[(i+1)%3].y - j2});
                 }
                if(paralel) return 1;
              //   cout << "pased" << i2 << " " << j2 << endl;
                 for(auto vert : bermud){
                      if(i2 == vert.x && j2 == vert.y) return 1;
                 }
                 int talbai = cross({bermud[1].x - bermud[0].x, bermud[1].y - bermud[0].y}, {bermud[2].x - bermud[0].x, bermud[2].y - bermud[0].y});
                 if(sum == talbai){
                       return 0;
                 }

                 if(i2 == 300 && j2 == 300){
                    //  cout << paralel << endl;
                    //  cout << i1 << " " << j1 << endl;
                 }
              //   print({i2, j2});
                // cout << talbai << " " << sum << endl;
                 return 1;
          };
          queue<Point> q;
          q.push({n - 1, 0});
          vector<vector<int>> d(n, vector<int>(n, 1e9));
          d[n - 1][0] = 0;
          while(!q.empty()){
               auto [x, y] = q.front(); q.pop();
            //   cout << x << " " << y << endl;
               for(int i = -1; i <= 1; i++){
                   for(int j = -1; j <= 1; j++){
                         if(check(x, y, x + i, y + j) && d[x][y] + 1 < d[x + i][y + j]){
                              //  cout  << x + i << " " << y + j << endl;
                              d[x + i][y + j] = d[x][y] + 1;
                              q.push({x + i, y + j});

                         }
                   }
               }
          }

          for(auto row : d){
           //  for(auto el : row) cout << el << " ";
             // cout << '\n';
          }

          if(d[0][n - 1] > 1e8) {
               cout << "-1\n";
               continue;
          } else cout << d[0][n - 1] << '\n';
     }

}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3888kb

input:

3
0.5 1.5 1.5 1.5 1 0.5
.#.
...
..#
3
0.5 1.5 1.5 1.5 1 0.5
.#.
..#
..#

output:

3
-1

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3824kb

input:

3
0.5 0.5 1 -0.5 1.5 0.5
##.
##.
...
3
1 0.5 0.5 1 1.5 1
.#.
#.#
...
3
0.5 1.5 1.5 1.5 1 0.5
.#.
...
..#
3
0.5 1.5 1.5 1.5 1 0.5
.#.
..#
..#
10
4 6 5 6 5 4
..........
..........
..........
..........
..........
..........
..........
..........
..........
..........
10
4.5 4.2 4.2 6.2 4.8 6.2
..........

output:

3
3
3
-1
10
10
9
9
-1
11
-1
18
3
3
2

result:

wrong answer 1st lines differ - expected: '-1', found: '3'