# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
896743 |
2024-01-02T03:59:06 Z |
LCJLY |
Mecho (IOI09_mecho) |
C++14 |
|
328 ms |
20976 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;
void solve(){
int n,k;
cin >> n >> k;
string arr[n];
for(int x=0;x<n;x++){
cin >> arr[x];
}
int l=0;
int r=n*n;
int best=-1;
int mid;
pii start;
pii done;
int dist[n+5][n+5];
memset(dist,-1,sizeof(dist));
queue<pii>q;
for(int x=0;x<n;x++){
for(int y=0;y<n;y++){
if(arr[x][y]=='H'){
q.push({x,y});
dist[x][y]=0;
}
else if(arr[x][y]=='M') start={x,y};
else if(arr[x][y]=='D') done={x,y};
}
}
pii dir[4]={
{0,1},
{0,-1},
{1,0},
{-1,0},
};
while(!q.empty()){
pii cur=q.front();
q.pop();
for(auto it:dir){
int newx=cur.first+it.first;
int newy=cur.second+it.second;
if(newx<0||newy<0||newx>=n||newy>=n) continue;
if(dist[newx][newy]!=-1) continue;
if(arr[newx][newy]=='T') continue;
if(arr[newx][newy]=='D') continue;
dist[newx][newy]=dist[cur.first][cur.second]+1;
q.push({newx,newy});
}
}
dist[done.first][done.second]=1e15;
while(l<=r){
mid=(l+r)/2;
int dist2[n][n];
memset(dist2,-1,sizeof(dist2));
dist2[start.first][start.second]=k*mid;
if(mid<dist[start.first][start.second])q.push({start.first,start.second});
bool visited[n+5][n+5];
memset(visited,0,sizeof(visited));
for(int x=0;x<n;x++){
vector<pii>storage;
int target=(x+1+mid)*k;
while(!q.empty()){
pii cur=q.front();
q.pop();
if((dist2[cur.first][cur.second]+k-1)/k==x+mid+1&&x+mid+1<dist[cur.first][cur.second]){
storage.push_back({cur.first,cur.second});
visited[cur.first][cur.second]=1;
}
if(dist2[cur.first][cur.second]>=target) continue;
for(auto it:dir){
int newx=cur.first+it.first;
int newy=cur.second+it.second;
if(newx<0||newy<0||newx>=n||newy>=n) continue;
if(dist2[newx][newy]!=-1) continue;
if(arr[newx][newy]=='T') continue;
dist2[newx][newy]=dist2[cur.first][cur.second]+1;
q.push({newx,newy});
}
}
for(auto it:storage) q.push(it);
}
bool amos=false;
for(auto it:dir){
int newx=done.first+it.first;
int newy=done.second+it.second;
if(newx<0||newy<0||newx>=n||newy>=n) continue;
if(arr[newx][newy]=='G'||arr[newx][newy]=='M'){
if(visited[newx][newy]) amos=true;
}
}
if(amos){
best=mid;
l=mid+1;
}
else r=mid-1;
}
cout << best;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("out.txt", "w", stdout);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
106 ms |
12776 KB |
Output isn't correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
504 KB |
Output isn't correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
592 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
33 |
Correct |
10 ms |
2652 KB |
Output is correct |
34 |
Incorrect |
5 ms |
2652 KB |
Output isn't correct |
35 |
Correct |
28 ms |
3936 KB |
Output is correct |
36 |
Correct |
11 ms |
3164 KB |
Output is correct |
37 |
Incorrect |
7 ms |
3164 KB |
Output isn't correct |
38 |
Correct |
37 ms |
5360 KB |
Output is correct |
39 |
Correct |
16 ms |
4092 KB |
Output is correct |
40 |
Incorrect |
8 ms |
3928 KB |
Output isn't correct |
41 |
Correct |
51 ms |
6232 KB |
Output is correct |
42 |
Correct |
22 ms |
4768 KB |
Output is correct |
43 |
Incorrect |
10 ms |
4956 KB |
Output isn't correct |
44 |
Correct |
64 ms |
7796 KB |
Output is correct |
45 |
Correct |
25 ms |
5724 KB |
Output is correct |
46 |
Incorrect |
13 ms |
5920 KB |
Output isn't correct |
47 |
Correct |
79 ms |
9720 KB |
Output is correct |
48 |
Correct |
28 ms |
6744 KB |
Output is correct |
49 |
Incorrect |
14 ms |
6748 KB |
Output isn't correct |
50 |
Correct |
86 ms |
10896 KB |
Output is correct |
51 |
Correct |
34 ms |
7980 KB |
Output is correct |
52 |
Incorrect |
17 ms |
8024 KB |
Output isn't correct |
53 |
Correct |
113 ms |
12436 KB |
Output is correct |
54 |
Correct |
44 ms |
9048 KB |
Output is correct |
55 |
Incorrect |
20 ms |
9052 KB |
Output isn't correct |
56 |
Correct |
173 ms |
14052 KB |
Output is correct |
57 |
Correct |
50 ms |
10444 KB |
Output is correct |
58 |
Incorrect |
24 ms |
10420 KB |
Output isn't correct |
59 |
Correct |
199 ms |
19112 KB |
Output is correct |
60 |
Correct |
45 ms |
11612 KB |
Output is correct |
61 |
Incorrect |
26 ms |
11868 KB |
Output isn't correct |
62 |
Correct |
216 ms |
20212 KB |
Output is correct |
63 |
Incorrect |
153 ms |
11888 KB |
Output isn't correct |
64 |
Correct |
328 ms |
20828 KB |
Output is correct |
65 |
Incorrect |
264 ms |
11928 KB |
Output isn't correct |
66 |
Incorrect |
171 ms |
11888 KB |
Output isn't correct |
67 |
Incorrect |
175 ms |
11880 KB |
Output isn't correct |
68 |
Incorrect |
58 ms |
11856 KB |
Output isn't correct |
69 |
Correct |
83 ms |
13652 KB |
Output is correct |
70 |
Incorrect |
39 ms |
11856 KB |
Output isn't correct |
71 |
Incorrect |
35 ms |
11868 KB |
Output isn't correct |
72 |
Correct |
30 ms |
12232 KB |
Output is correct |
73 |
Correct |
31 ms |
12380 KB |
Output is correct |
74 |
Incorrect |
114 ms |
16356 KB |
Output isn't correct |
75 |
Incorrect |
85 ms |
12368 KB |
Output isn't correct |
76 |
Incorrect |
75 ms |
12368 KB |
Output isn't correct |
77 |
Incorrect |
84 ms |
12336 KB |
Output isn't correct |
78 |
Correct |
87 ms |
12332 KB |
Output is correct |
79 |
Incorrect |
116 ms |
16500 KB |
Output isn't correct |
80 |
Incorrect |
66 ms |
12112 KB |
Output isn't correct |
81 |
Incorrect |
75 ms |
12364 KB |
Output isn't correct |
82 |
Incorrect |
69 ms |
12372 KB |
Output isn't correct |
83 |
Incorrect |
101 ms |
12124 KB |
Output isn't correct |
84 |
Incorrect |
215 ms |
17452 KB |
Output isn't correct |
85 |
Incorrect |
96 ms |
12376 KB |
Output isn't correct |
86 |
Incorrect |
100 ms |
12312 KB |
Output isn't correct |
87 |
Incorrect |
104 ms |
12868 KB |
Output isn't correct |
88 |
Incorrect |
102 ms |
12432 KB |
Output isn't correct |
89 |
Incorrect |
182 ms |
20976 KB |
Output isn't correct |
90 |
Incorrect |
136 ms |
13332 KB |
Output isn't correct |
91 |
Incorrect |
102 ms |
13900 KB |
Output isn't correct |
92 |
Incorrect |
103 ms |
12440 KB |
Output isn't correct |