# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
309224 |
2020-10-02T22:33:54 Z |
sofapuden |
Mecho (IOI09_mecho) |
C++14 |
|
813 ms |
65540 KB |
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
int n, k;
bool ok = 0;
pair<int,int> sta, en;
vector<string> G;
vector<vector<int>> V;
vector<vector<int>> vis;
queue<pair<pair<int,int>,int>> Q;
auto cmp = [](pair<pair<int,int>,pair<int,int>> l, pair<pair<int,int>,pair<int,int>> r){
if(l.f.f != r.f.f)return l.f.f < r.f.f;
return l.f.s > r.f.s;
};
priority_queue<pair<pair<int,int>,pair<int,int>>, vector<pair<pair<int,int>,pair<int,int>>>, decltype(cmp)> PQ(cmp);
void fin(pair<pair<int,int>,pair<int,int>> now){
if(vis[now.s.f][now.s.s] < now.f.s)return;
vis[now.s.f][now.s.s] = now.f.s;
if(now.s == en){cout << now.f.f << "\n";ok = 1;return;}
if(now.s.f != n-1){
if(V[now.s.f+1][now.s.s] > now.f.s/k+now.f.s/k-1){
PQ.push({{min(V[now.s.f+1][now.s.s]-now.f.s/k-1,now.f.f), now.f.s+1},{now.s.f+1,now.s.s}});
}
}
if(now.s.s != n-1){
if(V[now.s.f][now.s.s+1] > now.f.s/k+now.f.s/k-1){
PQ.push({{min(V[now.s.f][now.s.s+1]-now.f.s/k-1,now.f.f), now.f.s+1},{now.s.f,now.s.s+1}});
}
}
if(now.s.f != 0){
if(V[now.s.f-1][now.s.s] > now.f.s/k+now.f.s/k-1){
PQ.push({{min(V[now.s.f-1][now.s.s]-now.f.s/k-1,now.f.f), now.f.s+1},{now.s.f-1,now.s.s}});
}
}
if(now.s.s != 0){
if(V[now.s.f][now.s.s-1] > (now.f.s/k)+now.f.s/k-1){
PQ.push({{min(V[now.s.f][now.s.s-1]-now.f.s/k-1,now.f.f), now.f.s+1},{now.s.f,now.s.s-1}});
}
}
}
void search(pair<pair<int,int>,int> now){
if(now.f.f < 0 || now.f.s < 0 || now.f.f >= n || now.f.s >= n)return;
if(V[now.f.f][now.f.s] != -1)return;
V[now.f.f][now.f.s] = now.s;
Q.push({{now.f.f-1,now.f.s},now.s+1});
Q.push({{now.f.f+1,now.f.s},now.s+1});
Q.push({{now.f.f,now.f.s-1},now.s+1});
Q.push({{now.f.f,now.f.s+1},now.s+1});
}
int main(){
cin >> n >> k;
G.resize(n);
V.resize(n, vector<int> (n,-1));
vis.resize(n, vector<int> (n, 100000));
for(auto &x : G)cin >> x;
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
if(G[i][j] == 'T')V[i][j] = -2;
if(G[i][j] == 'M')sta = {i,j};
if(G[i][j] == 'D'){en = {i,j};V[i][j] = 100000;}
if(G[i][j] == 'H')Q.push({{i,j},0});
}
}
while(!Q.empty()){
auto x = Q.front();
Q.pop();
search(x);
}
//for(int i = 0; i < n; ++i){
//for(int j = 0; j < n; ++j){
//cout << V[i][j] << " ";
//}
//cout << "\n";
//}
PQ.push({{V[sta.f][sta.s]-1, 0},sta});
while(!PQ.empty()){
auto x = PQ.top();
PQ.pop();
//cout << x.f.f << " " << x.f.s << " " << x.s.f << " " << x.s.s << "\n";
fin(x);
if(ok)break;
}
if(!ok)cout << -1 << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
7 |
Runtime error |
486 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
256 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Runtime error |
709 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
14 |
Runtime error |
645 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
15 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
16 |
Correct |
0 ms |
256 KB |
Output is correct |
17 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Incorrect |
12 ms |
1536 KB |
Output isn't correct |
34 |
Correct |
13 ms |
1408 KB |
Output is correct |
35 |
Runtime error |
419 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
36 |
Incorrect |
15 ms |
1792 KB |
Output isn't correct |
37 |
Correct |
16 ms |
1792 KB |
Output is correct |
38 |
Runtime error |
428 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
39 |
Incorrect |
20 ms |
2176 KB |
Output isn't correct |
40 |
Correct |
21 ms |
2304 KB |
Output is correct |
41 |
Runtime error |
432 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
42 |
Incorrect |
26 ms |
2688 KB |
Output isn't correct |
43 |
Correct |
25 ms |
2816 KB |
Output is correct |
44 |
Runtime error |
437 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
45 |
Incorrect |
34 ms |
3328 KB |
Output isn't correct |
46 |
Correct |
30 ms |
3200 KB |
Output is correct |
47 |
Runtime error |
456 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
48 |
Incorrect |
39 ms |
3832 KB |
Output isn't correct |
49 |
Correct |
35 ms |
3712 KB |
Output is correct |
50 |
Runtime error |
453 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
51 |
Incorrect |
45 ms |
4348 KB |
Output isn't correct |
52 |
Incorrect |
43 ms |
4344 KB |
Output isn't correct |
53 |
Runtime error |
458 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
54 |
Incorrect |
55 ms |
4864 KB |
Output isn't correct |
55 |
Incorrect |
52 ms |
4864 KB |
Output isn't correct |
56 |
Runtime error |
476 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
57 |
Incorrect |
62 ms |
5368 KB |
Output isn't correct |
58 |
Incorrect |
63 ms |
5504 KB |
Output isn't correct |
59 |
Runtime error |
488 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
60 |
Incorrect |
70 ms |
6264 KB |
Output isn't correct |
61 |
Incorrect |
74 ms |
6136 KB |
Output isn't correct |
62 |
Runtime error |
501 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
63 |
Incorrect |
78 ms |
6144 KB |
Output isn't correct |
64 |
Correct |
132 ms |
6144 KB |
Output is correct |
65 |
Correct |
133 ms |
6136 KB |
Output is correct |
66 |
Incorrect |
98 ms |
6136 KB |
Output isn't correct |
67 |
Correct |
94 ms |
6144 KB |
Output is correct |
68 |
Incorrect |
88 ms |
6392 KB |
Output isn't correct |
69 |
Correct |
98 ms |
6424 KB |
Output is correct |
70 |
Incorrect |
82 ms |
6392 KB |
Output isn't correct |
71 |
Incorrect |
78 ms |
6392 KB |
Output isn't correct |
72 |
Correct |
80 ms |
6392 KB |
Output is correct |
73 |
Runtime error |
474 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
74 |
Runtime error |
705 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
75 |
Runtime error |
596 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
76 |
Runtime error |
616 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
77 |
Runtime error |
813 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
78 |
Runtime error |
693 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
79 |
Runtime error |
698 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
80 |
Runtime error |
701 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
81 |
Runtime error |
708 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
82 |
Runtime error |
694 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
83 |
Runtime error |
745 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
84 |
Runtime error |
693 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
85 |
Runtime error |
718 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
86 |
Runtime error |
770 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
87 |
Runtime error |
675 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
88 |
Runtime error |
491 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
89 |
Runtime error |
704 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
90 |
Runtime error |
502 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
91 |
Runtime error |
494 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
92 |
Runtime error |
498 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |