Submission #912783

# Submission time Handle Problem Language Result Execution time Memory
912783 2024-01-19T22:23:29 Z Glauco Mecho (IOI09_mecho) C++17
84 / 100
260 ms 6132 KB
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, s; cin >> n >> s;
  vector<vector<char>> g(n, vector<char>(n));
  for(auto &i : g) for(auto &j : i) cin >> j;

  queue<array<int, 3>> q;
  pair<int, int> start;
  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){
    if(g[i][j] == 'M') start = {i, j};
    if(g[i][j] == 'H') q.push({i, j, 0});
  }

  vector<vector<int>> free(n, vector<int>(n, 1e9));
  while(!q.empty()){
    auto [x, y, d] = q.front(); q.pop();
    
    if(x < 0 || y < 0 || x >= n || y >= n) continue;
    if(g[x][y] != 'H' && g[x][y] != 'G') continue;
    if(free[x][y] != 1e9) continue;
    free[x][y] = d; 

    q.push({x+1, y, d+1});
    q.push({x-1, y, d+1});
    q.push({x, y+1, d+1});
    q.push({x, y-1, d+1});
  }

  int l = -1, r = n*n;
  while(l < r-1){
    int m = (l+r)/2;

    bool ok = 0;
    vector<vector<bool>> vis(n, vector<bool>(n));
    queue<array<int, 4>> b; b.push({start.first, start.second, m, s});
    while(!b.empty()){
      auto [x, y, d, st] = b.front(); b.pop();

      if(x < 0 || y < 0 || x >= n || y >= n) continue;

      if(st == 0){
        st = s;
        d++;
      }

      if(vis[x][y]) continue; vis[x][y] = 1;
      if(g[x][y] == 'T') continue;
      if(free[x][y] <= d) continue;
      
      if(g[x][y] == 'D'){
        ok = 1;
        break;
      }

      b.push({x+1, y, d, st-1});
      b.push({x-1, y, d, st-1});
      b.push({x, y+1, d, st-1});
      b.push({x, y-1, d, st-1});
    }

    if(ok) l = m;
    else r = m;
  }

  cout << l;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:48:7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   48 |       if(vis[x][y]) continue; vis[x][y] = 1;
      |       ^~
mecho.cpp:48:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   48 |       if(vis[x][y]) continue; vis[x][y] = 1;
      |                               ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 142 ms 4700 KB Output is correct
8 Correct 1 ms 432 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 1 ms 348 KB Output isn't correct
13 Incorrect 1 ms 348 KB Output isn't correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 432 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 600 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 7 ms 1140 KB Output is correct
34 Correct 9 ms 1116 KB Output is correct
35 Correct 42 ms 1220 KB Output is correct
36 Correct 9 ms 1216 KB Output is correct
37 Correct 10 ms 1372 KB Output is correct
38 Correct 44 ms 1280 KB Output is correct
39 Correct 12 ms 1628 KB Output is correct
40 Correct 12 ms 1624 KB Output is correct
41 Correct 61 ms 1728 KB Output is correct
42 Correct 14 ms 1880 KB Output is correct
43 Correct 16 ms 1880 KB Output is correct
44 Correct 75 ms 1964 KB Output is correct
45 Correct 17 ms 2144 KB Output is correct
46 Correct 18 ms 2140 KB Output is correct
47 Correct 83 ms 2136 KB Output is correct
48 Correct 20 ms 2644 KB Output is correct
49 Correct 21 ms 2644 KB Output is correct
50 Correct 111 ms 2696 KB Output is correct
51 Correct 27 ms 2908 KB Output is correct
52 Correct 24 ms 2972 KB Output is correct
53 Correct 125 ms 2904 KB Output is correct
54 Correct 28 ms 3412 KB Output is correct
55 Correct 29 ms 3416 KB Output is correct
56 Correct 152 ms 3388 KB Output is correct
57 Correct 31 ms 3676 KB Output is correct
58 Correct 32 ms 3676 KB Output is correct
59 Correct 174 ms 3928 KB Output is correct
60 Correct 36 ms 4188 KB Output is correct
61 Correct 36 ms 4188 KB Output is correct
62 Correct 194 ms 4188 KB Output is correct
63 Correct 147 ms 4272 KB Output is correct
64 Correct 260 ms 4184 KB Output is correct
65 Correct 211 ms 4396 KB Output is correct
66 Correct 162 ms 4180 KB Output is correct
67 Correct 166 ms 4248 KB Output is correct
68 Correct 72 ms 4420 KB Output is correct
69 Correct 72 ms 4284 KB Output is correct
70 Correct 57 ms 4420 KB Output is correct
71 Correct 65 ms 4420 KB Output is correct
72 Incorrect 53 ms 4176 KB Output isn't correct
73 Incorrect 120 ms 6132 KB Output isn't correct
74 Correct 96 ms 5724 KB Output is correct
75 Correct 120 ms 5720 KB Output is correct
76 Correct 104 ms 5964 KB Output is correct
77 Correct 112 ms 5804 KB Output is correct
78 Correct 126 ms 5720 KB Output is correct
79 Correct 82 ms 5540 KB Output is correct
80 Correct 108 ms 5724 KB Output is correct
81 Correct 115 ms 5712 KB Output is correct
82 Correct 122 ms 5984 KB Output is correct
83 Correct 136 ms 5300 KB Output is correct
84 Correct 124 ms 5468 KB Output is correct
85 Correct 128 ms 5468 KB Output is correct
86 Correct 125 ms 5464 KB Output is correct
87 Correct 126 ms 5456 KB Output is correct
88 Correct 132 ms 5200 KB Output is correct
89 Correct 140 ms 5292 KB Output is correct
90 Correct 141 ms 5200 KB Output is correct
91 Correct 137 ms 5200 KB Output is correct
92 Correct 154 ms 5204 KB Output is correct