Submission #912784

# Submission time Handle Problem Language Result Execution time Memory
912784 2024-01-19T22:24:50 Z Glauco Mecho (IOI09_mecho) C++17
84 / 100
213 ms 5272 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 = 1e8;
  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 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 1 ms 592 KB Output is correct
7 Correct 136 ms 4260 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 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 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 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 344 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 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 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 8 ms 860 KB Output is correct
34 Correct 8 ms 856 KB Output is correct
35 Correct 33 ms 1096 KB Output is correct
36 Correct 10 ms 1116 KB Output is correct
37 Correct 10 ms 1116 KB Output is correct
38 Correct 49 ms 1116 KB Output is correct
39 Correct 12 ms 1372 KB Output is correct
40 Correct 12 ms 1624 KB Output is correct
41 Correct 56 ms 1484 KB Output is correct
42 Correct 19 ms 1884 KB Output is correct
43 Correct 15 ms 1624 KB Output is correct
44 Correct 73 ms 1628 KB Output is correct
45 Correct 18 ms 1880 KB Output is correct
46 Correct 19 ms 1884 KB Output is correct
47 Correct 89 ms 2032 KB Output is correct
48 Correct 20 ms 2320 KB Output is correct
49 Correct 21 ms 2232 KB Output is correct
50 Correct 103 ms 2392 KB Output is correct
51 Correct 24 ms 2392 KB Output is correct
52 Correct 24 ms 2416 KB Output is correct
53 Correct 121 ms 2676 KB Output is correct
54 Correct 28 ms 2908 KB Output is correct
55 Correct 29 ms 2904 KB Output is correct
56 Correct 147 ms 2908 KB Output is correct
57 Correct 32 ms 3156 KB Output is correct
58 Correct 32 ms 3308 KB Output is correct
59 Correct 170 ms 3280 KB Output is correct
60 Correct 37 ms 3676 KB Output is correct
61 Correct 36 ms 3644 KB Output is correct
62 Correct 197 ms 3668 KB Output is correct
63 Correct 136 ms 3668 KB Output is correct
64 Correct 192 ms 3920 KB Output is correct
65 Correct 213 ms 3760 KB Output is correct
66 Correct 163 ms 3660 KB Output is correct
67 Correct 166 ms 3756 KB Output is correct
68 Correct 69 ms 3672 KB Output is correct
69 Correct 67 ms 3664 KB Output is correct
70 Correct 56 ms 3676 KB Output is correct
71 Correct 57 ms 3784 KB Output is correct
72 Incorrect 56 ms 3676 KB Output isn't correct
73 Incorrect 106 ms 5204 KB Output isn't correct
74 Correct 115 ms 5252 KB Output is correct
75 Correct 110 ms 5212 KB Output is correct
76 Correct 110 ms 5272 KB Output is correct
77 Correct 115 ms 5204 KB Output is correct
78 Correct 125 ms 5092 KB Output is correct
79 Correct 102 ms 5092 KB Output is correct
80 Correct 111 ms 5088 KB Output is correct
81 Correct 127 ms 4944 KB Output is correct
82 Correct 105 ms 4956 KB Output is correct
83 Correct 131 ms 4828 KB Output is correct
84 Correct 135 ms 4688 KB Output is correct
85 Correct 122 ms 4832 KB Output is correct
86 Correct 132 ms 4688 KB Output is correct
87 Correct 133 ms 4672 KB Output is correct
88 Correct 135 ms 4436 KB Output is correct
89 Correct 140 ms 4428 KB Output is correct
90 Correct 147 ms 4432 KB Output is correct
91 Correct 150 ms 4568 KB Output is correct
92 Correct 147 ms 4576 KB Output is correct