답안 #131472

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
131472 2019-07-17T07:36:48 Z dragonslayerit Mecho (IOI09_mecho) C++14
100 / 100
271 ms 7832 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;

bool check(int 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') 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});
      }
    }
  }
  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});
      }
    }
  }
  int low=-1,high=N*N;
  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:49: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:51:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s",grid[x]);
     ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 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 117 ms 7544 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 476 KB Output is correct
10 Correct 2 ms 476 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 888 KB Output is correct
13 Correct 2 ms 760 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 632 KB Output is correct
23 Correct 2 ms 760 KB Output is correct
24 Correct 2 ms 760 KB Output is correct
25 Correct 3 ms 760 KB Output is correct
26 Correct 3 ms 760 KB Output is correct
27 Correct 3 ms 872 KB Output is correct
28 Correct 3 ms 888 KB Output is correct
29 Correct 2 ms 888 KB Output is correct
30 Correct 2 ms 888 KB Output is correct
31 Correct 2 ms 1016 KB Output is correct
32 Correct 3 ms 1016 KB Output is correct
33 Correct 9 ms 3448 KB Output is correct
34 Correct 9 ms 3460 KB Output is correct
35 Correct 26 ms 3448 KB Output is correct
36 Correct 11 ms 3832 KB Output is correct
37 Correct 11 ms 3836 KB Output is correct
38 Correct 33 ms 3832 KB Output is correct
39 Correct 13 ms 4216 KB Output is correct
40 Correct 13 ms 4340 KB Output is correct
41 Correct 43 ms 4344 KB Output is correct
42 Correct 16 ms 4784 KB Output is correct
43 Correct 16 ms 4728 KB Output is correct
44 Correct 60 ms 4784 KB Output is correct
45 Correct 19 ms 5368 KB Output is correct
46 Correct 18 ms 5112 KB Output is correct
47 Correct 68 ms 5144 KB Output is correct
48 Correct 22 ms 5752 KB Output is correct
49 Correct 21 ms 5624 KB Output is correct
50 Correct 82 ms 5672 KB Output is correct
51 Correct 25 ms 6108 KB Output is correct
52 Correct 27 ms 6136 KB Output is correct
53 Correct 105 ms 6008 KB Output is correct
54 Correct 28 ms 6520 KB Output is correct
55 Correct 30 ms 6596 KB Output is correct
56 Correct 123 ms 6620 KB Output is correct
57 Correct 31 ms 7032 KB Output is correct
58 Correct 31 ms 6904 KB Output is correct
59 Correct 149 ms 6992 KB Output is correct
60 Correct 35 ms 7416 KB Output is correct
61 Correct 34 ms 7416 KB Output is correct
62 Correct 165 ms 7416 KB Output is correct
63 Correct 128 ms 7432 KB Output is correct
64 Correct 271 ms 7544 KB Output is correct
65 Correct 188 ms 7516 KB Output is correct
66 Correct 147 ms 7440 KB Output is correct
67 Correct 141 ms 7416 KB Output is correct
68 Correct 67 ms 7416 KB Output is correct
69 Correct 67 ms 7416 KB Output is correct
70 Correct 54 ms 7416 KB Output is correct
71 Correct 60 ms 7416 KB Output is correct
72 Correct 48 ms 7416 KB Output is correct
73 Correct 54 ms 7672 KB Output is correct
74 Correct 75 ms 7672 KB Output is correct
75 Correct 96 ms 7672 KB Output is correct
76 Correct 84 ms 7672 KB Output is correct
77 Correct 83 ms 7672 KB Output is correct
78 Correct 105 ms 7672 KB Output is correct
79 Correct 66 ms 7672 KB Output is correct
80 Correct 83 ms 7672 KB Output is correct
81 Correct 91 ms 7832 KB Output is correct
82 Correct 81 ms 7800 KB Output is correct
83 Correct 106 ms 7672 KB Output is correct
84 Correct 97 ms 7676 KB Output is correct
85 Correct 107 ms 7672 KB Output is correct
86 Correct 105 ms 7656 KB Output is correct
87 Correct 109 ms 7676 KB Output is correct
88 Correct 121 ms 7616 KB Output is correct
89 Correct 119 ms 7672 KB Output is correct
90 Correct 116 ms 7564 KB Output is correct
91 Correct 118 ms 7592 KB Output is correct
92 Correct 136 ms 7672 KB Output is correct