# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
341020 | 2020-12-28T22:20:06 Z | peuch | Mecho (IOI09_mecho) | C++17 | 1000 ms | 17408 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; 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] = temp * s; 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((dist[curx][cury] + s) / 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 = 0, fim = 1e18 + 10; if(!test(fim)) 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 | Incorrect | 1 ms | 364 KB | Output isn't correct |
2 | Incorrect | 1 ms | 364 KB | Output isn't correct |
3 | Incorrect | 1 ms | 364 KB | Output isn't correct |
4 | Incorrect | 1 ms | 364 KB | Output isn't correct |
5 | Incorrect | 1 ms | 492 KB | Output isn't correct |
6 | Incorrect | 1 ms | 492 KB | Output isn't correct |
7 | Incorrect | 65 ms | 17004 KB | Output isn't correct |
8 | Correct | 1 ms | 492 KB | Output is correct |
9 | Correct | 1 ms | 492 KB | Output is correct |
10 | Incorrect | 1 ms | 492 KB | Output isn't correct |
11 | Incorrect | 1 ms | 492 KB | Output isn't correct |
12 | Incorrect | 2 ms | 1132 KB | Output isn't correct |
13 | Incorrect | 1 ms | 1004 KB | Output isn't correct |
14 | Correct | 1 ms | 1132 KB | Output is correct |
15 | Incorrect | 1 ms | 620 KB | Output isn't correct |
16 | Correct | 1 ms | 620 KB | Output is correct |
17 | Incorrect | 1 ms | 620 KB | Output isn't correct |
18 | Correct | 1 ms | 620 KB | Output is correct |
19 | Incorrect | 1 ms | 748 KB | Output isn't correct |
20 | Correct | 1 ms | 768 KB | Output is correct |
21 | Incorrect | 1 ms | 876 KB | Output isn't correct |
22 | Incorrect | 1 ms | 876 KB | Output isn't correct |
23 | Incorrect | 1 ms | 1004 KB | Output isn't correct |
24 | Incorrect | 1 ms | 1004 KB | Output isn't correct |
25 | Incorrect | 1 ms | 1132 KB | Output isn't correct |
26 | Incorrect | 3 ms | 1132 KB | Output isn't correct |
27 | Incorrect | 1 ms | 1260 KB | Output isn't correct |
28 | Incorrect | 3 ms | 1260 KB | Output isn't correct |
29 | Incorrect | 1 ms | 1260 KB | Output isn't correct |
30 | Incorrect | 3 ms | 1260 KB | Output isn't correct |
31 | Incorrect | 3 ms | 1388 KB | Output isn't correct |
32 | Incorrect | 2 ms | 1388 KB | Output isn't correct |
33 | Incorrect | 12 ms | 6764 KB | Output isn't correct |
34 | Incorrect | 73 ms | 6860 KB | Output isn't correct |
35 | Incorrect | 135 ms | 6764 KB | Output isn't correct |
36 | Incorrect | 16 ms | 8044 KB | Output isn't correct |
37 | Incorrect | 82 ms | 8172 KB | Output isn't correct |
38 | Incorrect | 190 ms | 8172 KB | Output isn't correct |
39 | Incorrect | 19 ms | 9324 KB | Output isn't correct |
40 | Incorrect | 23 ms | 9324 KB | Output isn't correct |
41 | Incorrect | 23 ms | 9472 KB | Output isn't correct |
42 | Incorrect | 23 ms | 10732 KB | Output isn't correct |
43 | Incorrect | 116 ms | 10732 KB | Output isn't correct |
44 | Incorrect | 26 ms | 10732 KB | Output isn't correct |
45 | Incorrect | 37 ms | 11884 KB | Output isn't correct |
46 | Incorrect | 172 ms | 11756 KB | Output isn't correct |
47 | Incorrect | 477 ms | 11884 KB | Output isn't correct |
48 | Incorrect | 32 ms | 12780 KB | Output isn't correct |
49 | Incorrect | 31 ms | 12780 KB | Output isn't correct |
50 | Incorrect | 487 ms | 12864 KB | Output isn't correct |
51 | Incorrect | 36 ms | 13804 KB | Output isn't correct |
52 | Incorrect | 215 ms | 13804 KB | Output isn't correct |
53 | Incorrect | 44 ms | 13804 KB | Output isn't correct |
54 | Incorrect | 41 ms | 14828 KB | Output isn't correct |
55 | Incorrect | 42 ms | 14828 KB | Output isn't correct |
56 | Incorrect | 794 ms | 15032 KB | Output isn't correct |
57 | Incorrect | 47 ms | 15980 KB | Output isn't correct |
58 | Incorrect | 47 ms | 15852 KB | Output isn't correct |
59 | Incorrect | 849 ms | 15980 KB | Output isn't correct |
60 | Incorrect | 55 ms | 17004 KB | Output isn't correct |
61 | Incorrect | 368 ms | 17004 KB | Output isn't correct |
62 | Incorrect | 69 ms | 17004 KB | Output isn't correct |
63 | Incorrect | 66 ms | 17004 KB | Output isn't correct |
64 | Incorrect | 944 ms | 17004 KB | Output isn't correct |
65 | Incorrect | 70 ms | 17004 KB | Output isn't correct |
66 | Incorrect | 78 ms | 17004 KB | Output isn't correct |
67 | Correct | 67 ms | 17004 KB | Output is correct |
68 | Incorrect | 73 ms | 17132 KB | Output isn't correct |
69 | Incorrect | 767 ms | 17004 KB | Output isn't correct |
70 | Incorrect | 75 ms | 17004 KB | Output isn't correct |
71 | Correct | 188 ms | 17004 KB | Output is correct |
72 | Incorrect | 659 ms | 17132 KB | Output isn't correct |
73 | Incorrect | 78 ms | 17260 KB | Output isn't correct |
74 | Incorrect | 83 ms | 17408 KB | Output isn't correct |
75 | Correct | 274 ms | 17280 KB | Output is correct |
76 | Incorrect | 83 ms | 17260 KB | Output isn't correct |
77 | Incorrect | 82 ms | 17260 KB | Output isn't correct |
78 | Incorrect | 259 ms | 17388 KB | Output isn't correct |
79 | Execution timed out | 1094 ms | 17260 KB | Time limit exceeded |
80 | Correct | 257 ms | 17368 KB | Output is correct |
81 | Incorrect | 69 ms | 17132 KB | Output isn't correct |
82 | Incorrect | 69 ms | 17132 KB | Output isn't correct |
83 | Correct | 279 ms | 17260 KB | Output is correct |
84 | Incorrect | 68 ms | 17132 KB | Output isn't correct |
85 | Incorrect | 73 ms | 17132 KB | Output isn't correct |
86 | Correct | 284 ms | 17172 KB | Output is correct |
87 | Incorrect | 67 ms | 17132 KB | Output isn't correct |
88 | Incorrect | 67 ms | 17132 KB | Output isn't correct |
89 | Execution timed out | 1096 ms | 17124 KB | Time limit exceeded |
90 | Incorrect | 68 ms | 17132 KB | Output isn't correct |
91 | Execution timed out | 1079 ms | 17132 KB | Time limit exceeded |
92 | Execution timed out | 1090 ms | 17132 KB | Time limit exceeded |