# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
583541 |
2022-06-25T14:24:51 Z |
Trent |
Mecho (IOI09_mecho) |
C++14 |
|
284 ms |
7036 KB |
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define open(g) string _name_ = g; freopen((_name_ + ".in").c_str(), "r", stdin); freopen((_name_ + ".out").c_str(), "w", stdout)
#define printArr(a, len) for(int asdf = 0; asdf < (len); ++asdf) cout << (a)[asdf] << ' '; cout << '\n';
#define boost() cin.sync_with_stdio(0); cin.tie(0)
#define forR(i, x) for(int i = 0; i < x; ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(i) i.begin(), i.end()
#define pii pair<int, int>
#define vi vector<int>
#define si set<int>
#define usi unordered_set<int>
#define mii map<int, int>
#define umii unordered_map<int, int>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
const int MN = 810, INF = 1e9 + 10;
struct coord{int r, c;};
struct bear{int r, c, sl;};
bool vis[MN][MN];
int bee[MN][MN], ber[MN][MN]; // minimum # of minutes needed to end here
char grid[MN][MN];
int dir[4][2] = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}};
int n, s;
int mr, mc;
bool ib(int r, int c){return 0 <= r && r < n && 0 <= c && c < n;}
bool iv(int r, int c){return ib(r, c) && grid[r][c] != 'T';}
// t = number of minutes bear eats
bool pos(int t){
if(bee[mr][mc] == t) return false;
deque<bear> bfs = {{mr, mc, 0}};
forR(a, MN) forR(b, MN) vis[a][b] = false;
forR(a, MN) forR(b, MN) ber[a][b] = 0;
ber[mr][mc] = t;
vis[mr][mc] = true;
while(!bfs.empty()){
auto [r, c, sl] = bfs.front();
bfs.pop_front();
if(grid[r][c] == 'D') {
return true;
}
for(auto [rc, cc] : dir){
auto [nr, nc] = pii{r+rc, c+cc};
int dis = ber[r][c] + (sl == 0);
// cout << r << ' ' << c << ' ' << sl << ' ' << nr << ' ' << nc << ' ' << dis << ' ' << bee[nr][nc] << '\n';
if(iv(nr, nc) && !vis[nr][nc] && (sl != 1 || dis < bee[nr][nc])){
ber[nr][nc] = dis;
vis[nr][nc] = true;
if(sl == 0) {
bfs.push_back({nr, nc, s-1});
} else bfs.push_back({nr, nc, sl-1});
}
}
}
return false;
}
signed main() {
cin >> n >> s;
deque<coord> bfs;
forR(r, n) forR(c, n){
cin >> grid[r][c];
if(grid[r][c] == 'H') {
bfs.push_back({r, c});
vis[r][c] = true;
} else if(grid[r][c] == 'M'){
mr=r, mc=c;
}
}
while(!bfs.empty()){
auto [r, c] = bfs.front();
bfs.pop_front();
for(auto [cr, cc] : dir){
auto [nr, nc] = pii {r + cr, c + cc};
if(iv(nr, nc) && grid[nr][nc] != 'D' && !vis[nr][nc]){
vis[nr][nc] = true;
bee[nr][nc] = bee[r][c] + 1;
bfs.push_back({nr, nc});
}
}
}
forR(r, MN) forR(c, MN) if(!vis[r][c]) bee[r][c] = INF;
if(!pos(0)) cout << "-1\n";
else {
// TODO fix hi
int lo=0, hi=MN * MN;
while(hi - lo > 1){
int mid = (lo + hi) / 2;
if(pos(mid)) lo = mid;
else hi = mid;
}
cout << lo << '\n';
}
}
Compilation message
mecho.cpp: In function 'bool pos(int)':
mecho.cpp:44:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
44 | auto [r, c, sl] = bfs.front();
| ^
mecho.cpp:49:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
49 | for(auto [rc, cc] : dir){
| ^
mecho.cpp:50:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
50 | auto [nr, nc] = pii{r+rc, c+cc};
| ^
mecho.cpp: In function 'int main()':
mecho.cpp:78:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
78 | auto [r, c] = bfs.front();
| ^
mecho.cpp:80:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
80 | for(auto [cr, cc] : dir){
| ^
mecho.cpp:81:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
81 | auto [nr, nc] = pii {r + cr, c + cc};
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
5972 KB |
Output isn't correct |
2 |
Incorrect |
6 ms |
5972 KB |
Output isn't correct |
3 |
Incorrect |
6 ms |
5972 KB |
Output isn't correct |
4 |
Incorrect |
5 ms |
5972 KB |
Output isn't correct |
5 |
Incorrect |
7 ms |
5972 KB |
Output isn't correct |
6 |
Incorrect |
5 ms |
6100 KB |
Output isn't correct |
7 |
Incorrect |
131 ms |
6792 KB |
Output isn't correct |
8 |
Incorrect |
5 ms |
6100 KB |
Output isn't correct |
9 |
Correct |
5 ms |
6096 KB |
Output is correct |
10 |
Correct |
5 ms |
6100 KB |
Output is correct |
11 |
Incorrect |
5 ms |
5972 KB |
Output isn't correct |
12 |
Incorrect |
6 ms |
6136 KB |
Output isn't correct |
13 |
Incorrect |
6 ms |
6124 KB |
Output isn't correct |
14 |
Incorrect |
6 ms |
6100 KB |
Output isn't correct |
15 |
Incorrect |
8 ms |
6100 KB |
Output isn't correct |
16 |
Incorrect |
5 ms |
6100 KB |
Output isn't correct |
17 |
Incorrect |
6 ms |
6100 KB |
Output isn't correct |
18 |
Incorrect |
6 ms |
6100 KB |
Output isn't correct |
19 |
Incorrect |
5 ms |
6100 KB |
Output isn't correct |
20 |
Incorrect |
5 ms |
6100 KB |
Output isn't correct |
21 |
Incorrect |
5 ms |
6100 KB |
Output isn't correct |
22 |
Incorrect |
5 ms |
6100 KB |
Output isn't correct |
23 |
Incorrect |
5 ms |
6100 KB |
Output isn't correct |
24 |
Incorrect |
5 ms |
6100 KB |
Output isn't correct |
25 |
Incorrect |
6 ms |
6100 KB |
Output isn't correct |
26 |
Incorrect |
7 ms |
6140 KB |
Output isn't correct |
27 |
Incorrect |
5 ms |
6100 KB |
Output isn't correct |
28 |
Incorrect |
6 ms |
6052 KB |
Output isn't correct |
29 |
Incorrect |
6 ms |
6080 KB |
Output isn't correct |
30 |
Incorrect |
8 ms |
6100 KB |
Output isn't correct |
31 |
Incorrect |
5 ms |
6100 KB |
Output isn't correct |
32 |
Incorrect |
6 ms |
6100 KB |
Output isn't correct |
33 |
Incorrect |
14 ms |
6332 KB |
Output isn't correct |
34 |
Incorrect |
15 ms |
6356 KB |
Output isn't correct |
35 |
Incorrect |
35 ms |
6292 KB |
Output isn't correct |
36 |
Incorrect |
16 ms |
6320 KB |
Output isn't correct |
37 |
Incorrect |
15 ms |
6356 KB |
Output isn't correct |
38 |
Incorrect |
55 ms |
6388 KB |
Output isn't correct |
39 |
Incorrect |
17 ms |
6336 KB |
Output isn't correct |
40 |
Incorrect |
21 ms |
6424 KB |
Output isn't correct |
41 |
Incorrect |
60 ms |
6432 KB |
Output isn't correct |
42 |
Incorrect |
24 ms |
6388 KB |
Output isn't correct |
43 |
Incorrect |
26 ms |
6464 KB |
Output isn't correct |
44 |
Incorrect |
67 ms |
6468 KB |
Output isn't correct |
45 |
Incorrect |
25 ms |
6500 KB |
Output isn't correct |
46 |
Incorrect |
26 ms |
6440 KB |
Output isn't correct |
47 |
Incorrect |
81 ms |
6472 KB |
Output isn't correct |
48 |
Incorrect |
30 ms |
6488 KB |
Output isn't correct |
49 |
Incorrect |
30 ms |
6464 KB |
Output isn't correct |
50 |
Incorrect |
112 ms |
6672 KB |
Output isn't correct |
51 |
Incorrect |
32 ms |
6488 KB |
Output isn't correct |
52 |
Incorrect |
31 ms |
6556 KB |
Output isn't correct |
53 |
Incorrect |
100 ms |
6588 KB |
Output isn't correct |
54 |
Incorrect |
34 ms |
6508 KB |
Output isn't correct |
55 |
Incorrect |
36 ms |
6504 KB |
Output isn't correct |
56 |
Incorrect |
133 ms |
6708 KB |
Output isn't correct |
57 |
Incorrect |
44 ms |
6604 KB |
Output isn't correct |
58 |
Incorrect |
41 ms |
6588 KB |
Output isn't correct |
59 |
Incorrect |
149 ms |
6584 KB |
Output isn't correct |
60 |
Incorrect |
45 ms |
6660 KB |
Output isn't correct |
61 |
Incorrect |
47 ms |
6592 KB |
Output isn't correct |
62 |
Incorrect |
166 ms |
6828 KB |
Output isn't correct |
63 |
Correct |
138 ms |
6688 KB |
Output is correct |
64 |
Correct |
284 ms |
6700 KB |
Output is correct |
65 |
Incorrect |
204 ms |
6656 KB |
Output isn't correct |
66 |
Correct |
197 ms |
6604 KB |
Output is correct |
67 |
Correct |
68 ms |
6700 KB |
Output is correct |
68 |
Incorrect |
99 ms |
6688 KB |
Output isn't correct |
69 |
Correct |
111 ms |
6688 KB |
Output is correct |
70 |
Incorrect |
69 ms |
6604 KB |
Output isn't correct |
71 |
Incorrect |
72 ms |
6604 KB |
Output isn't correct |
72 |
Incorrect |
71 ms |
6724 KB |
Output isn't correct |
73 |
Incorrect |
87 ms |
6936 KB |
Output isn't correct |
74 |
Incorrect |
203 ms |
7036 KB |
Output isn't correct |
75 |
Incorrect |
104 ms |
6888 KB |
Output isn't correct |
76 |
Incorrect |
99 ms |
6940 KB |
Output isn't correct |
77 |
Incorrect |
98 ms |
6860 KB |
Output isn't correct |
78 |
Incorrect |
138 ms |
6856 KB |
Output isn't correct |
79 |
Incorrect |
213 ms |
6948 KB |
Output isn't correct |
80 |
Incorrect |
95 ms |
6860 KB |
Output isn't correct |
81 |
Incorrect |
105 ms |
6916 KB |
Output isn't correct |
82 |
Incorrect |
104 ms |
6976 KB |
Output isn't correct |
83 |
Incorrect |
160 ms |
6912 KB |
Output isn't correct |
84 |
Incorrect |
199 ms |
6912 KB |
Output isn't correct |
85 |
Incorrect |
108 ms |
6820 KB |
Output isn't correct |
86 |
Incorrect |
116 ms |
6916 KB |
Output isn't correct |
87 |
Incorrect |
122 ms |
6916 KB |
Output isn't correct |
88 |
Incorrect |
145 ms |
6860 KB |
Output isn't correct |
89 |
Incorrect |
161 ms |
6748 KB |
Output isn't correct |
90 |
Incorrect |
136 ms |
6860 KB |
Output isn't correct |
91 |
Incorrect |
138 ms |
6732 KB |
Output isn't correct |
92 |
Incorrect |
138 ms |
6860 KB |
Output isn't correct |