# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
341019 | 2020-12-28T22:16:43 Z | peuch | Mecho (IOI09_mecho) | C++17 | 435 ms | 27000 KB |
#include<bits/stdc++.h> using namespace std; const int MAXN = 10010; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int n; long long s; int hx, hy; int mx, my; char grid[MAXN][MAXN]; long long beeDist[MAXN][MAXN]; int marc[MAXN][MAXN]; long long dist[MAXN][MAXN]; void preCalc(); bool test(long long temp); long long bb(); int main(){ scanf("%d %lld", &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("%lld\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] = 2e18; 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(long long 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 + (dist[curx][cury] + 1) / 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]; } long long bb(){ long long ini = 1, fim = 1e18 + 10; if(!test(ini)) return -1; while(ini != fim){ long long 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 | 492 KB | Output is correct |
5 | Incorrect | 1 ms | 492 KB | Output isn't correct |
6 | Correct | 1 ms | 492 KB | Output is correct |
7 | Correct | 363 ms | 26860 KB | Output is correct |
8 | Correct | 1 ms | 620 KB | Output is correct |
9 | Correct | 1 ms | 620 KB | Output is correct |
10 | Correct | 1 ms | 620 KB | Output is correct |
11 | Correct | 1 ms | 620 KB | Output is correct |
12 | Incorrect | 2 ms | 1388 KB | Output isn't correct |
13 | Incorrect | 1 ms | 1260 KB | Output isn't correct |
14 | Correct | 1 ms | 1388 KB | Output is correct |
15 | Correct | 1 ms | 620 KB | Output is correct |
16 | Correct | 1 ms | 620 KB | Output is correct |
17 | Correct | 1 ms | 748 KB | Output is correct |
18 | Correct | 1 ms | 748 KB | Output is correct |
19 | Correct | 1 ms | 876 KB | Output is correct |
20 | Correct | 1 ms | 876 KB | Output is correct |
21 | Correct | 1 ms | 1004 KB | Output is correct |
22 | Correct | 1 ms | 1004 KB | Output is correct |
23 | Correct | 2 ms | 1260 KB | Output is correct |
24 | Correct | 1 ms | 1260 KB | Output is correct |
25 | Correct | 2 ms | 1388 KB | Output is correct |
26 | Correct | 2 ms | 1388 KB | Output is correct |
27 | Correct | 2 ms | 1516 KB | Output is correct |
28 | Correct | 2 ms | 1516 KB | Output is correct |
29 | Correct | 2 ms | 1644 KB | Output is correct |
30 | Correct | 2 ms | 1644 KB | Output is correct |
31 | Correct | 2 ms | 1644 KB | Output is correct |
32 | Correct | 2 ms | 1644 KB | Output is correct |
33 | Correct | 22 ms | 8556 KB | Output is correct |
34 | Correct | 23 ms | 8556 KB | Output is correct |
35 | Correct | 51 ms | 8684 KB | Output is correct |
36 | Correct | 31 ms | 10220 KB | Output is correct |
37 | Correct | 31 ms | 10220 KB | Output is correct |
38 | Correct | 68 ms | 10220 KB | Output is correct |
39 | Correct | 37 ms | 11884 KB | Output is correct |
40 | Correct | 39 ms | 11904 KB | Output is correct |
41 | Correct | 91 ms | 11884 KB | Output is correct |
42 | Correct | 45 ms | 13676 KB | Output is correct |
43 | Correct | 47 ms | 13676 KB | Output is correct |
44 | Correct | 119 ms | 13676 KB | Output is correct |
45 | Correct | 55 ms | 15596 KB | Output is correct |
46 | Correct | 56 ms | 15596 KB | Output is correct |
47 | Correct | 156 ms | 15680 KB | Output is correct |
48 | Correct | 67 ms | 17536 KB | Output is correct |
49 | Correct | 68 ms | 17516 KB | Output is correct |
50 | Correct | 198 ms | 17516 KB | Output is correct |
51 | Correct | 85 ms | 19820 KB | Output is correct |
52 | Correct | 86 ms | 19692 KB | Output is correct |
53 | Correct | 243 ms | 19692 KB | Output is correct |
54 | Correct | 98 ms | 21868 KB | Output is correct |
55 | Correct | 107 ms | 21868 KB | Output is correct |
56 | Correct | 306 ms | 21996 KB | Output is correct |
57 | Correct | 119 ms | 24320 KB | Output is correct |
58 | Correct | 127 ms | 24172 KB | Output is correct |
59 | Correct | 362 ms | 24300 KB | Output is correct |
60 | Correct | 141 ms | 26764 KB | Output is correct |
61 | Correct | 143 ms | 26604 KB | Output is correct |
62 | Correct | 435 ms | 26604 KB | Output is correct |
63 | Incorrect | 87 ms | 26604 KB | Output isn't correct |
64 | Correct | 416 ms | 26860 KB | Output is correct |
65 | Correct | 335 ms | 26604 KB | Output is correct |
66 | Correct | 312 ms | 26732 KB | Output is correct |
67 | Correct | 86 ms | 26604 KB | Output is correct |
68 | Incorrect | 89 ms | 26604 KB | Output isn't correct |
69 | Correct | 196 ms | 26732 KB | Output is correct |
70 | Correct | 161 ms | 26732 KB | Output is correct |
71 | Correct | 167 ms | 26732 KB | Output is correct |
72 | Incorrect | 167 ms | 26604 KB | Output isn't correct |
73 | Incorrect | 207 ms | 26848 KB | Output isn't correct |
74 | Correct | 290 ms | 26912 KB | Output is correct |
75 | Correct | 266 ms | 26860 KB | Output is correct |
76 | Correct | 241 ms | 26860 KB | Output is correct |
77 | Correct | 253 ms | 26860 KB | Output is correct |
78 | Correct | 103 ms | 27000 KB | Output is correct |
79 | Correct | 255 ms | 26860 KB | Output is correct |
80 | Correct | 244 ms | 26860 KB | Output is correct |
81 | Correct | 253 ms | 26860 KB | Output is correct |
82 | Correct | 235 ms | 26860 KB | Output is correct |
83 | Incorrect | 118 ms | 26732 KB | Output isn't correct |
84 | Correct | 295 ms | 26732 KB | Output is correct |
85 | Correct | 289 ms | 26860 KB | Output is correct |
86 | Correct | 293 ms | 26732 KB | Output is correct |
87 | Correct | 269 ms | 26988 KB | Output is correct |
88 | Incorrect | 103 ms | 26732 KB | Output isn't correct |
89 | Correct | 329 ms | 26732 KB | Output is correct |
90 | Correct | 331 ms | 26792 KB | Output is correct |
91 | Correct | 326 ms | 26732 KB | Output is correct |
92 | Correct | 335 ms | 26732 KB | Output is correct |