# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
960609 |
2024-04-10T17:00:03 Z |
LmaoLmao |
Mecho (IOI09_mecho) |
C++14 |
|
119 ms |
15652 KB |
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
using ll = long long;
using ii = pair<ll, ll>;
const int N = 1e6+5;
const int INF = 1e9;
ll d[1000][1000],m[1000][1000],n,s;
char a[1000][1000];
ll dx[4]={1,0,0,-1};
ll dy[4]={0,1,-1,0};
ii pos,h;
bool bfs(ll x) {
if (d[pos.fi][pos.se] - x * s <= 0) return 0;
queue<ii> q;
q.push(pos);
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
m[i][j]=0;
}
}
while(!q.empty()) {
ii u=q.front();
q.pop();
for(int i=0;i<4;i++) {
ii v={u.fi+dx[i],u.se+dy[i]};
if(v.fi<0 || v.fi>=n || v.se<0 || v.se>=n) continue;
if(m[v.fi][v.se]==0 && a[v.fi][v.se]!='T' &&
d[v.fi][v.se]-x*s>m[u.fi][u.se]+1 && a[v.fi][v.se]!='M') {
m[v.fi][v.se]=m[u.fi][u.se]+1;
q.push(v);
}
}
}
if(m[h.fi][h.se]>0) return 1; else return 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
queue<ii> q;
cin >> n >> s;
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
cin >> a[i][j];
if(a[i][j]=='H') {
q.push({i,j});
}
if(a[i][j]=='M') pos={i,j};
if(a[i][j]=='D') h={i,j};
}
}
while(!q.empty()) {
ii u=q.front();
q.pop();
for(int i=0;i<4;i++) {
ii v={u.fi+dx[i],u.se+dy[i]};
if(v.fi<0 || v.fi>=n || v.se<0 || v.se>=n) continue;
if(d[v.fi][v.se]==0 && a[v.fi][v.se]!='T' && a[v.fi][v.se]!='H' && a[v.fi][v.se]!='D') {
d[v.fi][v.se]=d[u.fi][u.se]+s;
q.push(v);
}
}
}
d[h.fi][h.se] = (int)1e18;
ll l=1,r=10000000,ans=-1;
while(l<=r) {
ll m=(l+r)/2;
if(bfs(m)) {
ans=m;
l=m+1;
}
else {
r=m-1;
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
50 ms |
15196 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2708 KB |
Output is correct |
13 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2652 KB |
Output is correct |
20 |
Correct |
1 ms |
2652 KB |
Output is correct |
21 |
Correct |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2648 KB |
Output is correct |
24 |
Correct |
1 ms |
2648 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
2652 KB |
Output is correct |
29 |
Correct |
1 ms |
2652 KB |
Output is correct |
30 |
Correct |
1 ms |
2652 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2908 KB |
Output is correct |
33 |
Correct |
4 ms |
6492 KB |
Output is correct |
34 |
Correct |
4 ms |
6748 KB |
Output is correct |
35 |
Correct |
14 ms |
7124 KB |
Output is correct |
36 |
Correct |
5 ms |
6748 KB |
Output is correct |
37 |
Correct |
4 ms |
7260 KB |
Output is correct |
38 |
Correct |
18 ms |
7544 KB |
Output is correct |
39 |
Correct |
6 ms |
9304 KB |
Output is correct |
40 |
Correct |
6 ms |
9564 KB |
Output is correct |
41 |
Correct |
23 ms |
10072 KB |
Output is correct |
42 |
Correct |
8 ms |
9860 KB |
Output is correct |
43 |
Correct |
11 ms |
10188 KB |
Output is correct |
44 |
Correct |
28 ms |
10588 KB |
Output is correct |
45 |
Correct |
9 ms |
9816 KB |
Output is correct |
46 |
Correct |
10 ms |
10832 KB |
Output is correct |
47 |
Correct |
32 ms |
11096 KB |
Output is correct |
48 |
Correct |
9 ms |
10164 KB |
Output is correct |
49 |
Correct |
9 ms |
10708 KB |
Output is correct |
50 |
Correct |
41 ms |
11344 KB |
Output is correct |
51 |
Correct |
12 ms |
10636 KB |
Output is correct |
52 |
Correct |
11 ms |
11100 KB |
Output is correct |
53 |
Correct |
56 ms |
11868 KB |
Output is correct |
54 |
Correct |
13 ms |
12892 KB |
Output is correct |
55 |
Correct |
18 ms |
13660 KB |
Output is correct |
56 |
Correct |
63 ms |
14168 KB |
Output is correct |
57 |
Correct |
15 ms |
13148 KB |
Output is correct |
58 |
Correct |
15 ms |
13960 KB |
Output is correct |
59 |
Correct |
75 ms |
14712 KB |
Output is correct |
60 |
Correct |
15 ms |
13608 KB |
Output is correct |
61 |
Correct |
15 ms |
14372 KB |
Output is correct |
62 |
Correct |
87 ms |
15104 KB |
Output is correct |
63 |
Incorrect |
73 ms |
14936 KB |
Output isn't correct |
64 |
Correct |
108 ms |
14940 KB |
Output is correct |
65 |
Correct |
119 ms |
15108 KB |
Output is correct |
66 |
Correct |
90 ms |
15100 KB |
Output is correct |
67 |
Correct |
79 ms |
14936 KB |
Output is correct |
68 |
Incorrect |
37 ms |
14928 KB |
Output isn't correct |
69 |
Correct |
36 ms |
14936 KB |
Output is correct |
70 |
Correct |
41 ms |
15416 KB |
Output is correct |
71 |
Correct |
32 ms |
14928 KB |
Output is correct |
72 |
Correct |
30 ms |
15144 KB |
Output is correct |
73 |
Correct |
26 ms |
15452 KB |
Output is correct |
74 |
Correct |
36 ms |
15652 KB |
Output is correct |
75 |
Correct |
44 ms |
15400 KB |
Output is correct |
76 |
Correct |
41 ms |
15452 KB |
Output is correct |
77 |
Correct |
46 ms |
15640 KB |
Output is correct |
78 |
Correct |
47 ms |
15452 KB |
Output is correct |
79 |
Correct |
36 ms |
15436 KB |
Output is correct |
80 |
Correct |
40 ms |
15452 KB |
Output is correct |
81 |
Correct |
47 ms |
15452 KB |
Output is correct |
82 |
Correct |
44 ms |
15600 KB |
Output is correct |
83 |
Incorrect |
48 ms |
15440 KB |
Output isn't correct |
84 |
Correct |
44 ms |
15508 KB |
Output is correct |
85 |
Correct |
62 ms |
15512 KB |
Output is correct |
86 |
Correct |
49 ms |
15448 KB |
Output is correct |
87 |
Correct |
50 ms |
15524 KB |
Output is correct |
88 |
Incorrect |
50 ms |
15192 KB |
Output isn't correct |
89 |
Correct |
48 ms |
15196 KB |
Output is correct |
90 |
Correct |
59 ms |
15192 KB |
Output is correct |
91 |
Correct |
58 ms |
15408 KB |
Output is correct |
92 |
Correct |
49 ms |
15192 KB |
Output is correct |