# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
309229 |
2020-10-02T22:44:34 Z |
sofapuden |
Mecho (IOI09_mecho) |
C++14 |
|
811 ms |
65544 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-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-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-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-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, 1000000));
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] = 1000000;}
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 |
1 ms |
512 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
384 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
4 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
256 KB |
Output is correct |
7 |
Runtime error |
490 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Incorrect |
1 ms |
256 KB |
Output isn't correct |
9 |
Correct |
1 ms |
256 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 |
641 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
14 |
Runtime error |
649 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
15 |
Incorrect |
0 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 |
0 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 |
423 ms |
65540 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 |
422 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
39 |
Incorrect |
20 ms |
2304 KB |
Output isn't correct |
40 |
Correct |
20 ms |
2176 KB |
Output is correct |
41 |
Runtime error |
435 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
42 |
Incorrect |
24 ms |
2816 KB |
Output isn't correct |
43 |
Correct |
25 ms |
2816 KB |
Output is correct |
44 |
Runtime error |
443 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
45 |
Incorrect |
30 ms |
3320 KB |
Output isn't correct |
46 |
Correct |
30 ms |
3200 KB |
Output is correct |
47 |
Runtime error |
450 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
48 |
Incorrect |
34 ms |
3840 KB |
Output isn't correct |
49 |
Correct |
35 ms |
3716 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 |
40 ms |
4344 KB |
Output isn't correct |
52 |
Correct |
42 ms |
4352 KB |
Output is correct |
53 |
Runtime error |
462 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
54 |
Incorrect |
47 ms |
4864 KB |
Output isn't correct |
55 |
Correct |
47 ms |
4864 KB |
Output is correct |
56 |
Runtime error |
473 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
57 |
Incorrect |
53 ms |
5504 KB |
Output isn't correct |
58 |
Correct |
58 ms |
5752 KB |
Output is correct |
59 |
Runtime error |
498 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
60 |
Incorrect |
61 ms |
6136 KB |
Output isn't correct |
61 |
Correct |
63 ms |
6136 KB |
Output is correct |
62 |
Runtime error |
490 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
63 |
Correct |
128 ms |
6136 KB |
Output is correct |
64 |
Correct |
133 ms |
6240 KB |
Output is correct |
65 |
Correct |
135 ms |
6272 KB |
Output is correct |
66 |
Incorrect |
122 ms |
6140 KB |
Output isn't correct |
67 |
Correct |
108 ms |
6136 KB |
Output is correct |
68 |
Correct |
94 ms |
6392 KB |
Output is correct |
69 |
Correct |
98 ms |
6392 KB |
Output is correct |
70 |
Correct |
90 ms |
6392 KB |
Output is correct |
71 |
Correct |
89 ms |
6396 KB |
Output is correct |
72 |
Correct |
79 ms |
6392 KB |
Output is correct |
73 |
Runtime error |
480 ms |
65544 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 |
595 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
76 |
Runtime error |
609 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
77 |
Runtime error |
811 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
78 |
Runtime error |
696 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
79 |
Runtime error |
699 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
80 |
Runtime error |
700 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
81 |
Runtime error |
706 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
82 |
Runtime error |
695 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
83 |
Runtime error |
740 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 |
732 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
86 |
Runtime error |
779 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
87 |
Runtime error |
675 ms |
65536 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
88 |
Runtime error |
492 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
89 |
Runtime error |
717 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
90 |
Runtime error |
505 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
91 |
Runtime error |
504 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
92 |
Runtime error |
501 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |