# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
530714 |
2022-02-26T14:27:30 Z |
Alan |
Mecho (IOI09_mecho) |
C++17 |
|
1000 ms |
6576 KB |
#include <bits/stdc++.h>
#define I using
#define WA using namespace std;
#define on using ll = long long;
#define Test(x) int AlanIQ = -(x);
#define should ld =
#define quit long double;
#define OI int
#define forever main
#define Alan cin.tie(0);
#define fai(x) ios::ios_base::sync_with_stdio(!x);
#define Sharky return
#define orz 0;
WA on Test (109)
struct bee {
int r, c, t;
};
I should quit OI forever () {
Alan fai (true)
int n, s;
char ch;
cin >> n >> s;
int grid[n][n], best[n][n], startr, startc, endr, endc;
queue<bee> q;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> ch;
best[i][j] = -1;
if (ch == 'T') grid[i][j] = 1e9;
else if (ch == 'G') grid[i][j] = 0;
else if (ch == 'M') {
startr = i;
startc = j;
grid[i][j] = 0;
} else if (ch == 'D') {
endr = i;
endc = j;
grid[i][j] = 1e8;
} else if (ch == 'H') {
q.push({i, j, 0});
grid[i][j] = 1e9;
}
}
}
while (!q.empty()) {
int r = q.front().r;
int c = q.front().c;
int t = q.front().t;
q.pop();
if (c < n-1 && !grid[r][c+1]) {q.push({r, c+1, t+1}); grid[r][c+1] = t+1;}
if (c > 0 && !grid[r][c-1]) {q.push({r, c-1, t+1}); grid[r][c-1] = t+1;}
if (r < n-1 && !grid[r+1][c]) {q.push({r+1, c, t+1}); grid[r+1][c] = t+1;}
if (r > 0 && !grid[r-1][c]) {q.push({r-1, c, t+1}); grid[r-1][c] = t+1;}
}
best[startr][startc] = 1e9;
q.push({startr, startc, 0});
while (!q.empty()) {
int r = q.front().r;
int c = q.front().c;
int t = q.front().t;
int ttt = (t+2) / s + !!((t+2) % s);
int cur = best[r][c];
q.pop();
if (c < n-1 && grid[r][c+1] != 1e9 && min(cur, grid[r][c+1]-ttt) > best[r][c+1]) {q.push({r, c+1, t+1}); best[r][c+1] = min(cur, grid[r][c+1]-ttt);}
if (c > 0 && grid[r][c-1] != 1e9 && min(cur, grid[r][c-1]-ttt) > best[r][c-1]) {q.push({r, c-1, t+1}); best[r][c-1] = min(cur, grid[r][c-1]-ttt);}
if (r < n-1 && grid[r+1][c] != 1e9 && min(cur, grid[r+1][c]-ttt) > best[r+1][c]) {q.push({r+1, c, t+1}); best[r+1][c] = min(cur, grid[r+1][c]-ttt);}
if (r > 0 && grid[r-1][c] != 1e9 && min(cur, grid[r-1][c]-ttt) > best[r-1][c]) {q.push({r-1, c, t+1}); best[r-1][c] = min(cur, grid[r-1][c]-ttt);}
}
cout << (best[endr][endc] >= 0 ? best[endr][endc] : -1) << "\n";
Sharky orz
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:73:26: warning: 'endc' may be used uninitialized in this function [-Wmaybe-uninitialized]
73 | cout << (best[endr][endc] >= 0 ? best[endr][endc] : -1) << "\n";
| ~~~~~~~~~~~~~~~^
mecho.cpp:58:23: warning: 'startr' may be used uninitialized in this function [-Wmaybe-uninitialized]
58 | best[startr][startc] = 1e9;
| ~~~~~~~~~~~~~~~~~~~~~^~~~~
mecho.cpp:73:26: warning: 'endr' may be used uninitialized in this function [-Wmaybe-uninitialized]
73 | cout << (best[endr][endc] >= 0 ? best[endr][endc] : -1) << "\n";
| ~~~~~~~~~~~~~~~^
mecho.cpp:58:23: warning: 'startc' may be used uninitialized in this function [-Wmaybe-uninitialized]
58 | best[startr][startc] = 1e9;
| ~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
31 ms |
6064 KB |
Output is correct |
8 |
Correct |
0 ms |
320 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
308 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
312 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
320 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
4 ms |
1348 KB |
Output is correct |
34 |
Correct |
5 ms |
1388 KB |
Output is correct |
35 |
Correct |
98 ms |
1476 KB |
Output is correct |
36 |
Correct |
6 ms |
1696 KB |
Output is correct |
37 |
Correct |
5 ms |
1608 KB |
Output is correct |
38 |
Correct |
154 ms |
1876 KB |
Output is correct |
39 |
Correct |
6 ms |
1972 KB |
Output is correct |
40 |
Correct |
7 ms |
2072 KB |
Output is correct |
41 |
Correct |
230 ms |
2288 KB |
Output is correct |
42 |
Correct |
8 ms |
2508 KB |
Output is correct |
43 |
Correct |
10 ms |
2508 KB |
Output is correct |
44 |
Correct |
307 ms |
2764 KB |
Output is correct |
45 |
Correct |
9 ms |
2892 KB |
Output is correct |
46 |
Correct |
10 ms |
2952 KB |
Output is correct |
47 |
Correct |
389 ms |
3276 KB |
Output is correct |
48 |
Correct |
11 ms |
3404 KB |
Output is correct |
49 |
Correct |
12 ms |
3364 KB |
Output is correct |
50 |
Correct |
516 ms |
3856 KB |
Output is correct |
51 |
Correct |
14 ms |
4036 KB |
Output is correct |
52 |
Correct |
14 ms |
3916 KB |
Output is correct |
53 |
Correct |
641 ms |
4464 KB |
Output is correct |
54 |
Correct |
16 ms |
4608 KB |
Output is correct |
55 |
Correct |
15 ms |
4620 KB |
Output is correct |
56 |
Correct |
845 ms |
5124 KB |
Output is correct |
57 |
Correct |
16 ms |
5196 KB |
Output is correct |
58 |
Correct |
19 ms |
5260 KB |
Output is correct |
59 |
Execution timed out |
1036 ms |
5840 KB |
Time limit exceeded |
60 |
Correct |
20 ms |
5824 KB |
Output is correct |
61 |
Correct |
22 ms |
5920 KB |
Output is correct |
62 |
Execution timed out |
1065 ms |
6576 KB |
Time limit exceeded |
63 |
Correct |
37 ms |
5944 KB |
Output is correct |
64 |
Correct |
42 ms |
5836 KB |
Output is correct |
65 |
Correct |
49 ms |
5944 KB |
Output is correct |
66 |
Correct |
37 ms |
6064 KB |
Output is correct |
67 |
Correct |
34 ms |
5956 KB |
Output is correct |
68 |
Correct |
29 ms |
5968 KB |
Output is correct |
69 |
Correct |
30 ms |
5936 KB |
Output is correct |
70 |
Correct |
28 ms |
5964 KB |
Output is correct |
71 |
Correct |
31 ms |
5964 KB |
Output is correct |
72 |
Incorrect |
34 ms |
5948 KB |
Output isn't correct |
73 |
Incorrect |
29 ms |
6340 KB |
Output isn't correct |
74 |
Correct |
51 ms |
6212 KB |
Output is correct |
75 |
Correct |
35 ms |
6328 KB |
Output is correct |
76 |
Correct |
30 ms |
6348 KB |
Output is correct |
77 |
Correct |
32 ms |
6292 KB |
Output is correct |
78 |
Correct |
30 ms |
6220 KB |
Output is correct |
79 |
Correct |
219 ms |
6192 KB |
Output is correct |
80 |
Correct |
41 ms |
6304 KB |
Output is correct |
81 |
Correct |
29 ms |
6324 KB |
Output is correct |
82 |
Correct |
72 ms |
6296 KB |
Output is correct |
83 |
Correct |
28 ms |
6220 KB |
Output is correct |
84 |
Correct |
85 ms |
6240 KB |
Output is correct |
85 |
Correct |
108 ms |
6240 KB |
Output is correct |
86 |
Correct |
153 ms |
6236 KB |
Output is correct |
87 |
Correct |
43 ms |
6220 KB |
Output is correct |
88 |
Correct |
81 ms |
6172 KB |
Output is correct |
89 |
Correct |
264 ms |
6204 KB |
Output is correct |
90 |
Correct |
40 ms |
6168 KB |
Output is correct |
91 |
Correct |
49 ms |
6060 KB |
Output is correct |
92 |
Correct |
31 ms |
6044 KB |
Output is correct |