# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
499619 |
2021-12-29T05:18:18 Z |
_AnKahng |
Mecho (IOI09_mecho) |
C++14 |
|
147 ms |
4612 KB |
#include<bits/stdc++.h>
#define fi first
#define sc second
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int H[] = {-1,-1,1,1};
const int M = 805;
int n,s,f[M][M];
bool cx[M][M];
pair<int,int> st,fn;
string a[M];
struct dota{
int x,y,d;
};
void BFS_hive(){
queue<dota> q;
memset(cx,false,sizeof(cx));
fo(i,1,n)
fo(j,1,n) {
if(a[i][j] != 'T') cx[i][j] = true;
if(a[i][j] == 'H') q.push({i,j,0}), f[i][j] = 0, cx[i][j] = false;
}
while(!q.empty()){
int x = q.front().x, y = q.front().y, d = q.front().d;
q.pop();
f[x][y] = d;
int xi,yi;
fo(k,0,3){
if(k % 2) xi = x + H[k], yi = y;
else xi = x, yi = y + H[k];
if(cx[xi][yi]) q.push({xi,yi,d+1}), cx[xi][yi] = false;
}
}
}
bool check(int t){
queue<dota> q;
memset(cx,false,sizeof(cx));
fo(i,1,n)
fo(j,1,n) if(a[i][j] != 'T') cx[i][j] = true;
q.push({st.fi,st.sc,0});
cx[st.fi][st.sc] = false;
while(!q.empty()){
int x = q.front().x, y = q.front().y, d = q.front().d;
q.pop();
if(x == fn.fi && y == fn.sc) return true;
int xi,yi;
fo(k,0,3){
if(k % 2) xi = x + H[k], yi = y;
else xi = x, yi = y + H[k];
if(cx[xi][yi] && (d + 1) / s < f[xi][yi] - t) q.push({xi,yi,d+1}), cx[xi][yi] = false;
}
}
return false;
}
int main()
{
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin >> n >> s;
fo(i,1,n) cin >> a[i], a[i] = "*" + a[i];
fo(i,1,n)
fo(j,1,n)
if(a[i][j] == 'M') st = {i,j};
else if(a[i][j] == 'D') fn = {i,j};
BFS_hive();
//fo(i,1,n) fo(j,1,n) cout << f[i][j]<<" \n"[j == n];
int l = 0, r = n, mid,res;
while(l <= r){
mid = (l + r) / 2;
if(check(mid)) l = mid+1, res = mid;
else r = mid-1;
}
cout << res;
}
Compilation message
mecho.cpp: In function 'int main()':
mecho.cpp:77:13: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
77 | cout << res;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
3 |
Correct |
1 ms |
972 KB |
Output is correct |
4 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
7 |
Incorrect |
71 ms |
4312 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
9 |
Correct |
1 ms |
972 KB |
Output is correct |
10 |
Correct |
1 ms |
972 KB |
Output is correct |
11 |
Correct |
1 ms |
972 KB |
Output is correct |
12 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
15 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
16 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
17 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
18 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
19 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
20 |
Incorrect |
1 ms |
972 KB |
Output isn't correct |
21 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
22 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
23 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
24 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
25 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
26 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
27 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
28 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
29 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
30 |
Incorrect |
2 ms |
1100 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
1100 KB |
Output isn't correct |
32 |
Incorrect |
1 ms |
1228 KB |
Output isn't correct |
33 |
Incorrect |
5 ms |
2100 KB |
Output isn't correct |
34 |
Incorrect |
4 ms |
2124 KB |
Output isn't correct |
35 |
Correct |
14 ms |
2224 KB |
Output is correct |
36 |
Incorrect |
5 ms |
2380 KB |
Output isn't correct |
37 |
Incorrect |
5 ms |
2380 KB |
Output isn't correct |
38 |
Correct |
17 ms |
2416 KB |
Output is correct |
39 |
Incorrect |
6 ms |
2508 KB |
Output isn't correct |
40 |
Incorrect |
5 ms |
2624 KB |
Output isn't correct |
41 |
Correct |
22 ms |
2624 KB |
Output is correct |
42 |
Incorrect |
7 ms |
2764 KB |
Output isn't correct |
43 |
Incorrect |
8 ms |
2704 KB |
Output isn't correct |
44 |
Correct |
28 ms |
2764 KB |
Output is correct |
45 |
Incorrect |
8 ms |
3036 KB |
Output isn't correct |
46 |
Incorrect |
8 ms |
3020 KB |
Output isn't correct |
47 |
Correct |
34 ms |
3020 KB |
Output is correct |
48 |
Incorrect |
10 ms |
3148 KB |
Output isn't correct |
49 |
Incorrect |
9 ms |
3264 KB |
Output isn't correct |
50 |
Correct |
44 ms |
3276 KB |
Output is correct |
51 |
Incorrect |
12 ms |
3472 KB |
Output isn't correct |
52 |
Incorrect |
10 ms |
3480 KB |
Output isn't correct |
53 |
Correct |
48 ms |
3472 KB |
Output is correct |
54 |
Incorrect |
12 ms |
3660 KB |
Output isn't correct |
55 |
Incorrect |
13 ms |
3704 KB |
Output isn't correct |
56 |
Correct |
58 ms |
3712 KB |
Output is correct |
57 |
Incorrect |
14 ms |
3824 KB |
Output isn't correct |
58 |
Incorrect |
14 ms |
3852 KB |
Output isn't correct |
59 |
Correct |
61 ms |
3916 KB |
Output is correct |
60 |
Incorrect |
17 ms |
4088 KB |
Output isn't correct |
61 |
Incorrect |
17 ms |
4172 KB |
Output isn't correct |
62 |
Correct |
87 ms |
4084 KB |
Output is correct |
63 |
Correct |
93 ms |
4100 KB |
Output is correct |
64 |
Incorrect |
147 ms |
4152 KB |
Output isn't correct |
65 |
Correct |
128 ms |
4172 KB |
Output is correct |
66 |
Correct |
116 ms |
4152 KB |
Output is correct |
67 |
Incorrect |
99 ms |
4152 KB |
Output isn't correct |
68 |
Correct |
57 ms |
4192 KB |
Output is correct |
69 |
Correct |
55 ms |
4172 KB |
Output is correct |
70 |
Correct |
56 ms |
4196 KB |
Output is correct |
71 |
Correct |
66 ms |
4172 KB |
Output is correct |
72 |
Incorrect |
50 ms |
4172 KB |
Output isn't correct |
73 |
Incorrect |
29 ms |
4556 KB |
Output isn't correct |
74 |
Correct |
43 ms |
4572 KB |
Output is correct |
75 |
Correct |
44 ms |
4556 KB |
Output is correct |
76 |
Correct |
45 ms |
4572 KB |
Output is correct |
77 |
Correct |
43 ms |
4556 KB |
Output is correct |
78 |
Incorrect |
49 ms |
4508 KB |
Output isn't correct |
79 |
Correct |
53 ms |
4464 KB |
Output is correct |
80 |
Correct |
48 ms |
4428 KB |
Output is correct |
81 |
Correct |
49 ms |
4512 KB |
Output is correct |
82 |
Correct |
45 ms |
4612 KB |
Output is correct |
83 |
Correct |
55 ms |
4452 KB |
Output is correct |
84 |
Correct |
53 ms |
4428 KB |
Output is correct |
85 |
Correct |
55 ms |
4452 KB |
Output is correct |
86 |
Correct |
74 ms |
4420 KB |
Output is correct |
87 |
Correct |
74 ms |
4444 KB |
Output is correct |
88 |
Correct |
59 ms |
4300 KB |
Output is correct |
89 |
Correct |
74 ms |
4392 KB |
Output is correct |
90 |
Correct |
57 ms |
4300 KB |
Output is correct |
91 |
Correct |
58 ms |
4392 KB |
Output is correct |
92 |
Correct |
61 ms |
4312 KB |
Output is correct |