# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
341026 | 2020-12-28T22:26:08 Z | peuch | Mecho (IOI09_mecho) | C++17 | 279 ms | 10988 KB |
#include<bits/stdc++.h> using namespace std; const int MAXN = 1010; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int n, s; int hx, hy; int mx, my; char grid[MAXN][MAXN]; int beeDist[MAXN][MAXN]; int marc[MAXN][MAXN]; int dist[MAXN][MAXN]; void preCalc(); bool test(int temp); int bb(); int main(){ scanf("%d %d", &n, &s); for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ scanf(" %c", &grid[i][j]); if(grid[i][j] == 'D') hx = i, hy = j; if(grid[i][j] == 'M') mx = i, my = j; } } preCalc(); printf("%d\n", bb()); } void preCalc(){ queue<int> fila; for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ if(grid[i][j] != 'H') beeDist[i][j] = 1e8; else{ marc[i][j] = 1; fila.push(i); fila.push(j); } } } while(!fila.empty()){ int curx = fila.front(); fila.pop(); int cury = fila.front(); fila.pop(); for(int i = 0; i < 4; i++){ int vizx = curx + dx[i]; int vizy = cury + dy[i]; if(vizx <= 0 || vizx > n) continue; if(vizy <= 0 || vizy > n) continue; if(grid[vizx][vizy] == 'T') continue; if(grid[vizx][vizy] == 'D') continue; if(marc[vizx][vizy]) continue; marc[vizx][vizy] = 1; beeDist[vizx][vizy] = beeDist[curx][cury] + 1; fila.push(vizx); fila.push(vizy); } } } bool test(int temp){ queue<int> fila; for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++){ marc[i][j] = 0; dist[i][j] = 0; } } fila.push(mx); fila.push(my); marc[mx][my] = 1; dist[mx][my] = 0; while(!fila.empty()){ int curx = fila.front(); fila.pop(); int cury = fila.front(); fila.pop(); for(int i = 0; i < 4; i++){ int vizx = curx + dx[i]; int vizy = cury + dy[i]; if(vizx <= 0 || vizx > n) continue; if(vizy <= 0 || vizy > n) continue; if(grid[vizx][vizy] == 'T') continue; if(temp + 1 + dist[curx][cury] / s >= beeDist[vizx][vizy]) continue; if(marc[vizx][vizy]) continue; marc[vizx][vizy] = 1; dist[vizx][vizy] = dist[curx][cury] + 1; fila.push(vizx); fila.push(vizy); } } return marc[hx][hy]; } int bb(){ int ini = 0, fim = 1e8 + 10; if(!test(ini)) return -1; while(ini != fim){ int mid = (ini + fim) >> 1; if(ini == fim - 1) mid = fim; if(test(mid)) ini = mid; else fim = mid - 1; } return ini; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Incorrect | 1 ms | 492 KB | Output isn't correct |
6 | Incorrect | 1 ms | 492 KB | Output isn't correct |
7 | Incorrect | 190 ms | 10732 KB | Output isn't correct |
8 | Correct | 1 ms | 492 KB | Output is correct |
9 | Incorrect | 1 ms | 492 KB | Output isn't correct |
10 | Incorrect | 1 ms | 492 KB | Output isn't correct |
11 | Incorrect | 1 ms | 492 KB | Output isn't correct |
12 | Incorrect | 1 ms | 1132 KB | Output isn't correct |
13 | Correct | 1 ms | 1004 KB | Output is correct |
14 | Correct | 1 ms | 1132 KB | Output is correct |
15 | Correct | 1 ms | 620 KB | Output is correct |
16 | Incorrect | 1 ms | 620 KB | Output isn't correct |
17 | Correct | 1 ms | 620 KB | Output is correct |
18 | Incorrect | 1 ms | 620 KB | Output isn't correct |
19 | Correct | 1 ms | 748 KB | Output is correct |
20 | Incorrect | 1 ms | 748 KB | Output isn't correct |
21 | Correct | 1 ms | 876 KB | Output is correct |
22 | Incorrect | 1 ms | 876 KB | Output isn't correct |
23 | Correct | 1 ms | 1004 KB | Output is correct |
24 | Incorrect | 1 ms | 1004 KB | Output isn't correct |
25 | Correct | 1 ms | 1132 KB | Output is correct |
26 | Incorrect | 1 ms | 1132 KB | Output isn't correct |
27 | Correct | 2 ms | 1132 KB | Output is correct |
28 | Incorrect | 2 ms | 1132 KB | Output isn't correct |
29 | Correct | 2 ms | 1260 KB | Output is correct |
30 | Incorrect | 2 ms | 1260 KB | Output isn't correct |
31 | Correct | 2 ms | 1260 KB | Output is correct |
32 | Incorrect | 2 ms | 1260 KB | Output isn't correct |
33 | Correct | 16 ms | 4844 KB | Output is correct |
34 | Incorrect | 16 ms | 4844 KB | Output isn't correct |
35 | Incorrect | 38 ms | 4844 KB | Output isn't correct |
36 | Correct | 20 ms | 5484 KB | Output is correct |
37 | Incorrect | 21 ms | 5484 KB | Output isn't correct |
38 | Incorrect | 53 ms | 5484 KB | Output isn't correct |
39 | Correct | 24 ms | 6124 KB | Output is correct |
40 | Incorrect | 25 ms | 6124 KB | Output isn't correct |
41 | Incorrect | 69 ms | 6124 KB | Output isn't correct |
42 | Correct | 30 ms | 6764 KB | Output is correct |
43 | Incorrect | 33 ms | 6764 KB | Output isn't correct |
44 | Incorrect | 87 ms | 6764 KB | Output isn't correct |
45 | Correct | 39 ms | 7404 KB | Output is correct |
46 | Incorrect | 38 ms | 7532 KB | Output isn't correct |
47 | Incorrect | 111 ms | 7404 KB | Output isn't correct |
48 | Correct | 43 ms | 8044 KB | Output is correct |
49 | Incorrect | 46 ms | 8044 KB | Output isn't correct |
50 | Incorrect | 142 ms | 8172 KB | Output isn't correct |
51 | Correct | 54 ms | 8684 KB | Output is correct |
52 | Incorrect | 51 ms | 8684 KB | Output isn't correct |
53 | Incorrect | 171 ms | 8812 KB | Output isn't correct |
54 | Correct | 58 ms | 9324 KB | Output is correct |
55 | Incorrect | 62 ms | 9324 KB | Output isn't correct |
56 | Incorrect | 201 ms | 9324 KB | Output isn't correct |
57 | Correct | 67 ms | 9996 KB | Output is correct |
58 | Incorrect | 71 ms | 9964 KB | Output isn't correct |
59 | Incorrect | 222 ms | 9964 KB | Output isn't correct |
60 | Correct | 74 ms | 10604 KB | Output is correct |
61 | Incorrect | 78 ms | 10604 KB | Output isn't correct |
62 | Incorrect | 279 ms | 10732 KB | Output isn't correct |
63 | Incorrect | 71 ms | 10604 KB | Output isn't correct |
64 | Incorrect | 227 ms | 10732 KB | Output isn't correct |
65 | Incorrect | 227 ms | 10604 KB | Output isn't correct |
66 | Correct | 207 ms | 10604 KB | Output is correct |
67 | Correct | 75 ms | 10604 KB | Output is correct |
68 | Incorrect | 74 ms | 10604 KB | Output isn't correct |
69 | Incorrect | 109 ms | 10824 KB | Output isn't correct |
70 | Incorrect | 99 ms | 10604 KB | Output isn't correct |
71 | Incorrect | 99 ms | 10604 KB | Output isn't correct |
72 | Correct | 95 ms | 10732 KB | Output is correct |
73 | Correct | 108 ms | 10860 KB | Output is correct |
74 | Incorrect | 162 ms | 10864 KB | Output isn't correct |
75 | Incorrect | 168 ms | 10988 KB | Output isn't correct |
76 | Incorrect | 154 ms | 10988 KB | Output isn't correct |
77 | Incorrect | 156 ms | 10860 KB | Output isn't correct |
78 | Correct | 73 ms | 10860 KB | Output is correct |
79 | Incorrect | 162 ms | 10860 KB | Output isn't correct |
80 | Incorrect | 149 ms | 10860 KB | Output isn't correct |
81 | Incorrect | 154 ms | 10860 KB | Output isn't correct |
82 | Incorrect | 149 ms | 10988 KB | Output isn't correct |
83 | Incorrect | 75 ms | 10988 KB | Output isn't correct |
84 | Incorrect | 179 ms | 10860 KB | Output isn't correct |
85 | Incorrect | 187 ms | 10988 KB | Output isn't correct |
86 | Incorrect | 163 ms | 10860 KB | Output isn't correct |
87 | Incorrect | 186 ms | 10860 KB | Output isn't correct |
88 | Incorrect | 79 ms | 10732 KB | Output isn't correct |
89 | Incorrect | 191 ms | 10732 KB | Output isn't correct |
90 | Incorrect | 193 ms | 10732 KB | Output isn't correct |
91 | Incorrect | 188 ms | 10732 KB | Output isn't correct |
92 | Incorrect | 186 ms | 10732 KB | Output isn't correct |