# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
91074 |
2018-12-26T06:48:31 Z |
Retro3014 |
Mecho (IOI09_mecho) |
C++17 |
|
196 ms |
5484 KB |
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <deque>
#define MAX_N 800
struct S{
int x, y;
bool operator ==(const S &a)const{
return (x==a.x) && (y==a.y);
}
};
using namespace std;
int N, K;
string str[MAX_N+1];
bool type[MAX_N+1][MAX_N+1];
S M, D;
bool visited[MAX_N+1][MAX_N+1];
int dist[MAX_N+1][MAX_N+1];
bool chk(int t, int p){
S tmp={t, p};
if(tmp.x<0 || tmp.x>=N || tmp.y<0 || tmp.y>=N) return false;
if(visited[t][p]) return false;
if(type[t][p]) return false;
return true;
}
int dx[4]={0, 0, 1, -1}, dy[4]={1, -1, 0, 0};
deque<S> dq;
void BFS(){
for(int i=0; i<dq.size(); i++){
visited[dq[i].x][dq[i].y]=true;
}
while(!dq.empty()){
S now = dq.front();
dq.pop_front();
for(int k=0; k<4; k++){
if(chk(now.x+dx[k], now.y+dy[k]) && !(now.x+dx[k]==D.x && now.y+dy[k]==D.y)){
dist[now.x+dx[k]][now.y+dy[k]]=dist[now.x][now.y]+1;
visited[now.x+dx[k]][now.y+dy[k]]=true;
dq.push_back({now.x+dx[k], now.y+dy[k]});
}
}
}
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
visited[i][j]=false;
}
}
}
bool can(int T){
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
visited[i][j]=false;
}
}
int t=0;
dq.clear();
dq.push_back(M);
visited[M.x][M.y]=true;
while(!dq.empty()){
int sz=(int)dq.size();
while(sz--){
S now = dq.front();
dq.pop_front();
if(dist[now.x][now.y]>T){
if(now==D) return true;
for(int k=0; k<4; k++){
if(chk(now.x+dx[k], now.y+dy[k]) && dist[now.x+dx[k]][now.y+dy[k]]>T){
visited[now.x+dx[k]][now.y+dy[k]]=true;
dq.push_back({now.x+dx[k], now.y+dy[k]});
}
}
}
}
t++;
if(t==K){
t=0; T++;
}
}
return false;
}
int main(){
scanf("%d%d", &N, &K);
for(int i=0; i<N; i++){
cin>>str[i];
for(int j=0; j<N; j++){
if(str[i][j]=='T') type[i][j]=1;
else if(str[i][j]=='M') M={i, j};
else if(str[i][j]=='D') D={i, j};
else if(str[i][j]=='H'){
dq.push_back({i, j});
}
}
}
dist[D.x][D.y]=MAX_N*MAX_N+1;
BFS();
int s=0, e=N*N+1, mid;
while(s<e){
if(s==e-1){
if(can(e)){
s=e;
}else{
e=s;
}
}else{
mid=(s+e)/2;
if(can(mid)){
s=mid;
}else{
e=mid-1;
}
}
}
printf("%d", s);
return 0;
}
Compilation message
mecho.cpp: In function 'void BFS()':
mecho.cpp:36:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<dq.size(); i++){
~^~~~~~~~~~
mecho.cpp: In function 'int main()':
mecho.cpp:91:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &N, &K);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
500 KB |
Output is correct |
3 |
Correct |
2 ms |
500 KB |
Output is correct |
4 |
Correct |
2 ms |
520 KB |
Output is correct |
5 |
Correct |
2 ms |
532 KB |
Output is correct |
6 |
Correct |
2 ms |
660 KB |
Output is correct |
7 |
Correct |
119 ms |
5232 KB |
Output is correct |
8 |
Incorrect |
2 ms |
5232 KB |
Output isn't correct |
9 |
Correct |
2 ms |
5232 KB |
Output is correct |
10 |
Correct |
2 ms |
5232 KB |
Output is correct |
11 |
Correct |
2 ms |
5232 KB |
Output is correct |
12 |
Correct |
2 ms |
5232 KB |
Output is correct |
13 |
Correct |
2 ms |
5232 KB |
Output is correct |
14 |
Incorrect |
2 ms |
5232 KB |
Output isn't correct |
15 |
Correct |
2 ms |
5232 KB |
Output is correct |
16 |
Correct |
2 ms |
5232 KB |
Output is correct |
17 |
Correct |
2 ms |
5232 KB |
Output is correct |
18 |
Correct |
2 ms |
5232 KB |
Output is correct |
19 |
Correct |
2 ms |
5232 KB |
Output is correct |
20 |
Correct |
2 ms |
5232 KB |
Output is correct |
21 |
Correct |
2 ms |
5232 KB |
Output is correct |
22 |
Correct |
2 ms |
5232 KB |
Output is correct |
23 |
Correct |
2 ms |
5232 KB |
Output is correct |
24 |
Correct |
2 ms |
5232 KB |
Output is correct |
25 |
Correct |
2 ms |
5232 KB |
Output is correct |
26 |
Correct |
2 ms |
5232 KB |
Output is correct |
27 |
Correct |
2 ms |
5232 KB |
Output is correct |
28 |
Correct |
2 ms |
5232 KB |
Output is correct |
29 |
Correct |
2 ms |
5232 KB |
Output is correct |
30 |
Correct |
2 ms |
5232 KB |
Output is correct |
31 |
Correct |
2 ms |
5232 KB |
Output is correct |
32 |
Correct |
2 ms |
5232 KB |
Output is correct |
33 |
Correct |
9 ms |
5232 KB |
Output is correct |
34 |
Correct |
9 ms |
5232 KB |
Output is correct |
35 |
Correct |
28 ms |
5232 KB |
Output is correct |
36 |
Correct |
11 ms |
5232 KB |
Output is correct |
37 |
Correct |
11 ms |
5232 KB |
Output is correct |
38 |
Correct |
36 ms |
5232 KB |
Output is correct |
39 |
Correct |
13 ms |
5232 KB |
Output is correct |
40 |
Correct |
14 ms |
5232 KB |
Output is correct |
41 |
Correct |
46 ms |
5232 KB |
Output is correct |
42 |
Correct |
16 ms |
5232 KB |
Output is correct |
43 |
Correct |
17 ms |
5232 KB |
Output is correct |
44 |
Correct |
70 ms |
5232 KB |
Output is correct |
45 |
Correct |
19 ms |
5232 KB |
Output is correct |
46 |
Correct |
20 ms |
5232 KB |
Output is correct |
47 |
Correct |
69 ms |
5232 KB |
Output is correct |
48 |
Correct |
22 ms |
5232 KB |
Output is correct |
49 |
Correct |
23 ms |
5232 KB |
Output is correct |
50 |
Correct |
91 ms |
5232 KB |
Output is correct |
51 |
Correct |
25 ms |
5232 KB |
Output is correct |
52 |
Correct |
25 ms |
5232 KB |
Output is correct |
53 |
Correct |
99 ms |
5232 KB |
Output is correct |
54 |
Correct |
28 ms |
5232 KB |
Output is correct |
55 |
Correct |
30 ms |
5232 KB |
Output is correct |
56 |
Correct |
139 ms |
5232 KB |
Output is correct |
57 |
Correct |
34 ms |
5232 KB |
Output is correct |
58 |
Correct |
34 ms |
5232 KB |
Output is correct |
59 |
Correct |
152 ms |
5232 KB |
Output is correct |
60 |
Correct |
37 ms |
5232 KB |
Output is correct |
61 |
Correct |
38 ms |
5232 KB |
Output is correct |
62 |
Correct |
164 ms |
5248 KB |
Output is correct |
63 |
Correct |
116 ms |
5248 KB |
Output is correct |
64 |
Correct |
163 ms |
5248 KB |
Output is correct |
65 |
Correct |
196 ms |
5248 KB |
Output is correct |
66 |
Correct |
166 ms |
5248 KB |
Output is correct |
67 |
Incorrect |
144 ms |
5248 KB |
Output isn't correct |
68 |
Correct |
70 ms |
5248 KB |
Output is correct |
69 |
Correct |
77 ms |
5248 KB |
Output is correct |
70 |
Correct |
68 ms |
5248 KB |
Output is correct |
71 |
Correct |
69 ms |
5248 KB |
Output is correct |
72 |
Correct |
57 ms |
5248 KB |
Output is correct |
73 |
Correct |
60 ms |
5408 KB |
Output is correct |
74 |
Correct |
90 ms |
5408 KB |
Output is correct |
75 |
Correct |
95 ms |
5408 KB |
Output is correct |
76 |
Correct |
90 ms |
5412 KB |
Output is correct |
77 |
Correct |
84 ms |
5448 KB |
Output is correct |
78 |
Incorrect |
96 ms |
5448 KB |
Output isn't correct |
79 |
Correct |
71 ms |
5448 KB |
Output is correct |
80 |
Correct |
82 ms |
5448 KB |
Output is correct |
81 |
Correct |
92 ms |
5448 KB |
Output is correct |
82 |
Correct |
82 ms |
5448 KB |
Output is correct |
83 |
Correct |
98 ms |
5448 KB |
Output is correct |
84 |
Correct |
98 ms |
5448 KB |
Output is correct |
85 |
Correct |
109 ms |
5484 KB |
Output is correct |
86 |
Correct |
101 ms |
5484 KB |
Output is correct |
87 |
Correct |
103 ms |
5484 KB |
Output is correct |
88 |
Correct |
97 ms |
5484 KB |
Output is correct |
89 |
Correct |
102 ms |
5484 KB |
Output is correct |
90 |
Correct |
113 ms |
5484 KB |
Output is correct |
91 |
Correct |
127 ms |
5484 KB |
Output is correct |
92 |
Correct |
114 ms |
5484 KB |
Output is correct |