Submission #131460

# Submission time Handle Problem Language Result Execution time Memory
131460 2019-07-17T07:29:46 Z dragonslayerit Mecho (IOI09_mecho) C++14
53 / 100
224 ms 7800 KB
#include <cstdio>
#include <queue>
#include <tuple>

const int INF=1e9+7;

const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};

char grid[1005][1005];
int danger[1005][1005];

int dist[1005][1005];
int N,S;

void dump(int vs[1005][1005]){
  for(int x=0;x<N;x++){
    for(int y=0;y<N;y++){
      if(vs[x][y]!=INF){
	printf("%d",vs[x][y]);
      }else{
	printf("-");
      }
    }
    printf("\n");
  }
  printf("\n");
}

bool check(int start){
  //printf("check(%d)\n",start);
  for(int x=0;x<N;x++){
    for(int y=0;y<N;y++){
      dist[x][y]=INF;
    }
  }
  std::queue<std::pair<int,int> > mecho;
  for(int x=0;x<N;x++){
    for(int y=0;y<N;y++){
      if(grid[x][y]=='M'){
	dist[x][y]=0;
	mecho.push({x,y});
      }
    }
  }
  while(!mecho.empty()){
    int x,y;
    std::tie(x,y)=mecho.front();
    mecho.pop();
    if(dist[x][y]/S+start>=danger[x][y]) continue;
    if(grid[x][y]=='D'){
      //dump(dist);
      return true;
    }
    for(int d=0;d<4;d++){
      int x2=x+dx[d],y2=y+dy[d];
      if((grid[x2][y2]=='G'||grid[x2][y2]=='D')&&dist[x2][y2]==INF){
	dist[x2][y2]=dist[x][y]+1;
	mecho.push({x2,y2});
      }
    }
  }
  //dump(dist);
  return false;
}

int main(){
  scanf("%d %d",&N,&S);
  for(int x=0;x<N;x++){
    scanf("%s",grid[x]);
  }
  for(int x=0;x<N;x++){
    for(int y=0;y<N;y++){
      danger[x][y]=INF;
    }
  }
  std::queue<std::pair<int,int> > bees;
  for(int x=0;x<N;x++){
    for(int y=0;y<N;y++){
      if(grid[x][y]=='H'){
	danger[x][y]=0;
	bees.push({x,y});
      }
    }
  }
  while(!bees.empty()){
    int x,y;
    std::tie(x,y)=bees.front();
    bees.pop();
    for(int d=0;d<4;d++){
      int x2=x+dx[d],y2=y+dy[d];
      if((grid[x2][y2]=='G'||grid[x2][y2]=='M')&&danger[x2][y2]==INF){
	danger[x2][y2]=danger[x][y]+1;
	bees.push({x2,y2});
      }
    }
  }
  //dump(danger);
  int low=-1,high=N*2;
  while(high-low>1){
    int mid=(low+high)/2;
    if(check(mid)){
      low=mid;
    }else{
      high=mid;
    }
  }
  printf("%d\n",low);
  return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&N,&S);
   ~~~~~^~~~~~~~~~~~~~~
mecho.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s",grid[x]);
     ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 116 ms 7544 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Incorrect 2 ms 888 KB Output isn't correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 888 KB Output is correct
15 Incorrect 2 ms 504 KB Output isn't correct
16 Incorrect 2 ms 504 KB Output isn't correct
17 Incorrect 2 ms 504 KB Output isn't correct
18 Incorrect 2 ms 504 KB Output isn't correct
19 Incorrect 2 ms 508 KB Output isn't correct
20 Incorrect 2 ms 504 KB Output isn't correct
21 Incorrect 3 ms 632 KB Output isn't correct
22 Incorrect 3 ms 632 KB Output isn't correct
23 Incorrect 2 ms 764 KB Output isn't correct
24 Incorrect 3 ms 760 KB Output isn't correct
25 Incorrect 3 ms 888 KB Output isn't correct
26 Incorrect 5 ms 888 KB Output isn't correct
27 Incorrect 3 ms 888 KB Output isn't correct
28 Incorrect 3 ms 888 KB Output isn't correct
29 Incorrect 2 ms 888 KB Output isn't correct
30 Incorrect 2 ms 888 KB Output isn't correct
31 Incorrect 2 ms 888 KB Output isn't correct
32 Incorrect 3 ms 1016 KB Output isn't correct
33 Incorrect 8 ms 3448 KB Output isn't correct
34 Incorrect 8 ms 3448 KB Output isn't correct
35 Correct 23 ms 3448 KB Output is correct
36 Incorrect 9 ms 3804 KB Output isn't correct
37 Incorrect 9 ms 3832 KB Output isn't correct
38 Correct 32 ms 3832 KB Output is correct
39 Incorrect 11 ms 4344 KB Output isn't correct
40 Incorrect 11 ms 4344 KB Output isn't correct
41 Correct 40 ms 4472 KB Output is correct
42 Incorrect 12 ms 4728 KB Output isn't correct
43 Incorrect 12 ms 4856 KB Output isn't correct
44 Correct 52 ms 4728 KB Output is correct
45 Incorrect 15 ms 5112 KB Output isn't correct
46 Incorrect 15 ms 5112 KB Output isn't correct
47 Correct 63 ms 5240 KB Output is correct
48 Incorrect 17 ms 5596 KB Output isn't correct
49 Incorrect 19 ms 5596 KB Output isn't correct
50 Correct 97 ms 5616 KB Output is correct
51 Incorrect 22 ms 6140 KB Output isn't correct
52 Incorrect 20 ms 6136 KB Output isn't correct
53 Correct 99 ms 6148 KB Output is correct
54 Incorrect 22 ms 6520 KB Output isn't correct
55 Incorrect 22 ms 6544 KB Output isn't correct
56 Correct 127 ms 6648 KB Output is correct
57 Incorrect 25 ms 6904 KB Output isn't correct
58 Incorrect 24 ms 6904 KB Output isn't correct
59 Correct 138 ms 6996 KB Output is correct
60 Incorrect 35 ms 7416 KB Output isn't correct
61 Incorrect 30 ms 7416 KB Output isn't correct
62 Correct 160 ms 7416 KB Output is correct
63 Correct 125 ms 7416 KB Output is correct
64 Correct 184 ms 7436 KB Output is correct
65 Correct 224 ms 7372 KB Output is correct
66 Correct 166 ms 7444 KB Output is correct
67 Correct 149 ms 7516 KB Output is correct
68 Correct 73 ms 7416 KB Output is correct
69 Correct 62 ms 7476 KB Output is correct
70 Correct 50 ms 7416 KB Output is correct
71 Correct 49 ms 7496 KB Output is correct
72 Correct 41 ms 7416 KB Output is correct
73 Correct 54 ms 7676 KB Output is correct
74 Correct 69 ms 7672 KB Output is correct
75 Correct 73 ms 7672 KB Output is correct
76 Correct 83 ms 7672 KB Output is correct
77 Correct 83 ms 7672 KB Output is correct
78 Correct 88 ms 7708 KB Output is correct
79 Correct 69 ms 7672 KB Output is correct
80 Correct 70 ms 7684 KB Output is correct
81 Correct 84 ms 7672 KB Output is correct
82 Correct 73 ms 7672 KB Output is correct
83 Correct 105 ms 7656 KB Output is correct
84 Correct 94 ms 7544 KB Output is correct
85 Correct 99 ms 7800 KB Output is correct
86 Correct 103 ms 7672 KB Output is correct
87 Correct 94 ms 7672 KB Output is correct
88 Correct 101 ms 7684 KB Output is correct
89 Correct 105 ms 7544 KB Output is correct
90 Correct 113 ms 7672 KB Output is correct
91 Correct 111 ms 7544 KB Output is correct
92 Correct 99 ms 7672 KB Output is correct