Submission #914133

# Submission time Handle Problem Language Result Execution time Memory
914133 2024-01-21T09:10:11 Z mychecksedad Maze (JOI23_ho_t3) C++17
8 / 100
591 ms 43784 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 6e6+100, M = 1e5+10, K = 52, MX = 30;

int r, c, n, sx, sy, ex, ey, arr[4][2]={{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; 
string s[5000];
vector<vector<int>> dp;

void solve(){
  cin >> r >> c >> n >> sx >> sy >> ex >> ey;
  sx--, sy--, ex--, ey--;
  for(int i = 0; i < r; ++i) cin >> s[i];


  vector<vector<pair<int, int>>> C;
  vector<vector<int>> vis(r, vector<int>(c));
  vector<vector<array<int, 2>>> dist(r, vector<array<int, 2>>(c));
  vector<vector<int>> dp(r, vector<int>(c, MOD));
  for(int i = 0; i < r; ++i){
    for(int j = 0; j < c; ++j){
      if(s[i][j] == '#' || vis[i][j]) continue;
      queue<pair<int, int>> q;
      q.push({i, j});
      vis[i][j] = C.size() + 1;
      C.pb({});
      while(!q.empty()){
        int x = q.front().first, y = q.front().second;
        q.pop();
        C.back().pb({x, y});
        for(int l = 0; l < 4; ++l){
          int x1 = x + arr[l][0], x2 = y + arr[l][1];
          if(x1 >= 0 && x2 >= 0 && x1 < r && x2 < c && s[x1][x2] != '#' && !vis[x1][x2]){
            q.push({x1, x2});
            vis[x1][x2] = C.size();
          }
        }
      }
    }
  }
  auto comp = [&](const array<int, 2> &x, const array<int, 2> &y){
    return max(abs(dist[x[0]][x[1]][0]), abs(dist[x[0]][x[1]][1])) < max(abs(dist[y[0]][y[1]][0]), abs(dist[y[0]][y[1]][1]));
  };
  priority_queue<array<int, 2>, vector<array<int, 2>>, decltype(comp)> Q(comp);
  for(auto p: C[vis[sx][sy] - 1]){
    int x = 0, req = 4;
    for(int l = 0; l < 4; ++l){
      int a = arr[l][0] + p.first, b = arr[l][1] + p.second;
      if(a >= 0 && b >= 0 && a < r && b < c){
        if(vis[a][b] == vis[p.first][p.second]) ++x;
      }else --req;
    }
    dp[p.first][p.second] = 0;
    dist[p.first][p.second] = {0};
    if(x < req) Q.push({p.first, p.second});
  }
  int cur = 0;
  while(dp[ex][ey] == MOD){
    vector<pair<int, int>> Sn;

    while(!Q.empty()){
      int x = Q.top()[0], y = Q.top()[1]; Q.pop();
      // cout << x << ' '<< y << ' ' << cur << ' ' << dist[x][y][0] << ' ' << dist[x][y][1] << endl;

      int curx = dist[x][y][0], cury = dist[x][y][1];
      for(int l = 0; l < 4; ++l){
        int a = x + arr[l][0], b = y + arr[l][1];
        if(a >= 0 && b >= 0 && a < r && b < c){
          if(max(abs(curx + arr[l][0]), abs(cury + arr[l][1])) > n || abs(curx + arr[l][0]) + abs(cury + arr[l][1]) == 2*n){
            if(dp[a][b] == MOD && vis[a][b] > 0){
              for(auto p: C[vis[a][b] - 1]){
                dp[p.first][p.second] = cur + 1;
                Sn.pb(p);
              }
            }
            continue;
          }
          if(dp[a][b] < MOD){
            if(max(abs(dist[a][b][0]), abs(dist[a][b][1])) > max(abs(curx + arr[l][0]), abs(cury + arr[l][1]))){
              dist[a][b] = {curx + arr[l][0], cury + arr[l][1]};
            }
          }else{
            dp[a][b] = cur + 1;
            dist[a][b] = {curx + arr[l][0], cury + arr[l][1]};
            Sn.pb({a, b});
            Q.push({a, b});
          }
        }
      }
    }

    for(auto p: Sn){
      int x = 0, req = 4;
      for(int l = 0; l < 4; ++l){
        int a = arr[l][0] + p.first, b = arr[l][1] + p.second;
        if(a >= 0 && b >= 0 && a < r && b < c){
          if(dp[a][b] < MOD) ++x;
        }else --req;
      }
      if(x < req){
        Q.push({p.first, p.second});
        dist[p.first][p.second] = {0};
      }
    }
    ++cur;
  }
  // for(int i = 0; i < r; ++i){
  //   for(int j = 0 ;j < c; ++j) cout << dp[i][j] << ' ';
  //   en;
  // }
  cout << dp[ex][ey];
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
    en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 		

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:123:15: warning: unused variable 'aa' [-Wunused-variable]
  123 |   int tt = 1, aa;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 14 ms 1628 KB Output is correct
20 Correct 5 ms 1588 KB Output is correct
21 Correct 3 ms 2264 KB Output is correct
22 Correct 14 ms 2140 KB Output is correct
23 Correct 19 ms 1688 KB Output is correct
24 Correct 3 ms 2452 KB Output is correct
25 Correct 4 ms 1904 KB Output is correct
26 Correct 4 ms 2140 KB Output is correct
27 Correct 4 ms 2140 KB Output is correct
28 Correct 10 ms 1628 KB Output is correct
29 Correct 46 ms 3164 KB Output is correct
30 Correct 7 ms 2412 KB Output is correct
31 Correct 8 ms 5272 KB Output is correct
32 Correct 40 ms 4556 KB Output is correct
33 Correct 45 ms 3264 KB Output is correct
34 Correct 9 ms 4872 KB Output is correct
35 Correct 11 ms 3740 KB Output is correct
36 Correct 25 ms 4640 KB Output is correct
37 Correct 43 ms 4504 KB Output is correct
38 Correct 4 ms 3160 KB Output is correct
39 Correct 591 ms 28688 KB Output is correct
40 Correct 15 ms 4756 KB Output is correct
41 Correct 12 ms 6252 KB Output is correct
42 Correct 65 ms 5528 KB Output is correct
43 Correct 26 ms 7372 KB Output is correct
44 Correct 60 ms 19620 KB Output is correct
45 Correct 73 ms 19112 KB Output is correct
46 Correct 86 ms 43784 KB Output is correct
47 Correct 459 ms 40708 KB Output is correct
48 Correct 474 ms 26520 KB Output is correct
49 Correct 67 ms 42568 KB Output is correct
50 Correct 74 ms 31512 KB Output is correct
51 Correct 364 ms 39560 KB Output is correct
52 Correct 296 ms 40964 KB Output is correct
53 Correct 577 ms 26768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 856 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Incorrect 1 ms 604 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Incorrect 3 ms 1628 KB Output isn't correct
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 856 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Incorrect 1 ms 604 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 856 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Incorrect 1 ms 604 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 14 ms 1628 KB Output is correct
20 Correct 5 ms 1588 KB Output is correct
21 Correct 3 ms 2264 KB Output is correct
22 Correct 14 ms 2140 KB Output is correct
23 Correct 19 ms 1688 KB Output is correct
24 Correct 3 ms 2452 KB Output is correct
25 Correct 4 ms 1904 KB Output is correct
26 Correct 4 ms 2140 KB Output is correct
27 Correct 4 ms 2140 KB Output is correct
28 Correct 10 ms 1628 KB Output is correct
29 Correct 46 ms 3164 KB Output is correct
30 Correct 7 ms 2412 KB Output is correct
31 Correct 8 ms 5272 KB Output is correct
32 Correct 40 ms 4556 KB Output is correct
33 Correct 45 ms 3264 KB Output is correct
34 Correct 9 ms 4872 KB Output is correct
35 Correct 11 ms 3740 KB Output is correct
36 Correct 25 ms 4640 KB Output is correct
37 Correct 43 ms 4504 KB Output is correct
38 Correct 4 ms 3160 KB Output is correct
39 Correct 591 ms 28688 KB Output is correct
40 Correct 15 ms 4756 KB Output is correct
41 Correct 12 ms 6252 KB Output is correct
42 Correct 65 ms 5528 KB Output is correct
43 Correct 26 ms 7372 KB Output is correct
44 Correct 60 ms 19620 KB Output is correct
45 Correct 73 ms 19112 KB Output is correct
46 Correct 86 ms 43784 KB Output is correct
47 Correct 459 ms 40708 KB Output is correct
48 Correct 474 ms 26520 KB Output is correct
49 Correct 67 ms 42568 KB Output is correct
50 Correct 74 ms 31512 KB Output is correct
51 Correct 364 ms 39560 KB Output is correct
52 Correct 296 ms 40964 KB Output is correct
53 Correct 577 ms 26768 KB Output is correct
54 Correct 1 ms 600 KB Output is correct
55 Correct 0 ms 856 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 0 ms 604 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Incorrect 1 ms 604 KB Output isn't correct
62 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 14 ms 1628 KB Output is correct
20 Correct 5 ms 1588 KB Output is correct
21 Correct 3 ms 2264 KB Output is correct
22 Correct 14 ms 2140 KB Output is correct
23 Correct 19 ms 1688 KB Output is correct
24 Correct 3 ms 2452 KB Output is correct
25 Correct 4 ms 1904 KB Output is correct
26 Correct 4 ms 2140 KB Output is correct
27 Correct 4 ms 2140 KB Output is correct
28 Correct 10 ms 1628 KB Output is correct
29 Correct 46 ms 3164 KB Output is correct
30 Correct 7 ms 2412 KB Output is correct
31 Correct 8 ms 5272 KB Output is correct
32 Correct 40 ms 4556 KB Output is correct
33 Correct 45 ms 3264 KB Output is correct
34 Correct 9 ms 4872 KB Output is correct
35 Correct 11 ms 3740 KB Output is correct
36 Correct 25 ms 4640 KB Output is correct
37 Correct 43 ms 4504 KB Output is correct
38 Correct 4 ms 3160 KB Output is correct
39 Correct 591 ms 28688 KB Output is correct
40 Correct 15 ms 4756 KB Output is correct
41 Correct 12 ms 6252 KB Output is correct
42 Correct 65 ms 5528 KB Output is correct
43 Correct 26 ms 7372 KB Output is correct
44 Correct 60 ms 19620 KB Output is correct
45 Correct 73 ms 19112 KB Output is correct
46 Correct 86 ms 43784 KB Output is correct
47 Correct 459 ms 40708 KB Output is correct
48 Correct 474 ms 26520 KB Output is correct
49 Correct 67 ms 42568 KB Output is correct
50 Correct 74 ms 31512 KB Output is correct
51 Correct 364 ms 39560 KB Output is correct
52 Correct 296 ms 40964 KB Output is correct
53 Correct 577 ms 26768 KB Output is correct
54 Correct 1 ms 600 KB Output is correct
55 Correct 0 ms 856 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 0 ms 604 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Incorrect 1 ms 604 KB Output isn't correct
62 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 0 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 604 KB Output is correct
12 Correct 0 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 14 ms 1628 KB Output is correct
20 Correct 5 ms 1588 KB Output is correct
21 Correct 3 ms 2264 KB Output is correct
22 Correct 14 ms 2140 KB Output is correct
23 Correct 19 ms 1688 KB Output is correct
24 Correct 3 ms 2452 KB Output is correct
25 Correct 4 ms 1904 KB Output is correct
26 Correct 4 ms 2140 KB Output is correct
27 Correct 4 ms 2140 KB Output is correct
28 Correct 10 ms 1628 KB Output is correct
29 Correct 46 ms 3164 KB Output is correct
30 Correct 7 ms 2412 KB Output is correct
31 Correct 8 ms 5272 KB Output is correct
32 Correct 40 ms 4556 KB Output is correct
33 Correct 45 ms 3264 KB Output is correct
34 Correct 9 ms 4872 KB Output is correct
35 Correct 11 ms 3740 KB Output is correct
36 Correct 25 ms 4640 KB Output is correct
37 Correct 43 ms 4504 KB Output is correct
38 Correct 4 ms 3160 KB Output is correct
39 Correct 591 ms 28688 KB Output is correct
40 Correct 15 ms 4756 KB Output is correct
41 Correct 12 ms 6252 KB Output is correct
42 Correct 65 ms 5528 KB Output is correct
43 Correct 26 ms 7372 KB Output is correct
44 Correct 60 ms 19620 KB Output is correct
45 Correct 73 ms 19112 KB Output is correct
46 Correct 86 ms 43784 KB Output is correct
47 Correct 459 ms 40708 KB Output is correct
48 Correct 474 ms 26520 KB Output is correct
49 Correct 67 ms 42568 KB Output is correct
50 Correct 74 ms 31512 KB Output is correct
51 Correct 364 ms 39560 KB Output is correct
52 Correct 296 ms 40964 KB Output is correct
53 Correct 577 ms 26768 KB Output is correct
54 Correct 1 ms 600 KB Output is correct
55 Correct 0 ms 856 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 0 ms 604 KB Output is correct
58 Correct 1 ms 604 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Incorrect 1 ms 604 KB Output isn't correct
62 Halted 0 ms 0 KB -