답안 #583168

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583168 2022-06-24T23:23:54 Z HeyYouNotYouYou Mecho (IOI09_mecho) C++14
73 / 100
599 ms 16324 KB
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 801,INF=1e12;
int n , o, srcx, srcy, destx, desty, ar[N][N];
int dx[4]={0,-1,1,0};
int dy[4]={-1,0,0,1};
struct node{
  int x, y, dist;
};
bool valid1(int x, int y){
  if(x>=0 && x<n && y>=0 && y<n && (x!=srcx || y!=srcy) && (x!=destx || y!=desty)) return true;
  return false;
}
bool valid(int x, int y){
  if(x>=0 && x<n && y>=0 && y<n) return true;
  return false;
}
bool check(int mins)
{
  vector<pair<int,int>>hives;
  int arr[n][n];
  for(int i = 0 ; i < n ; i ++)
    for(int j = 0 ; j < n ; j ++)
      {
        arr[i][j]=ar[i][j];
        if(arr[i][j]==1) hives.push_back({i,j});
      }
  queue<pair<int,int>>q;
  int vis[n][n];
  memset(vis,0,sizeof vis);
  for(auto e : hives){
    q.push({e.first,e.second});
    vis[e.first][e.second]=1;
  }
 
  while(!q.empty())
  {
    int curx=q.front().first;
    int cury=q.front().second;
    q.pop();
    for(int i = 0 ; i < 4; i ++)
    {
      int gox = curx+dx[i], goy = cury+dy[i];
      if(valid(gox,goy) && !vis[gox][goy] && !arr[gox][goy]){
        vis[gox][goy]=1;
        arr[gox][goy]=arr[curx][cury]+1;
        q.push({gox,goy});
      }
    }
  }
 
  memset(vis,0,sizeof vis);
  q.push({srcx,srcy});
  vis[srcx][srcy]=1;
  if(arr[srcx][srcy]<=mins) return false;
  arr[srcx][srcy]=1;
  while(!q.empty()){
    int curx=q.front().first;
    int cury=q.front().second;
    if(curx==destx&&cury==desty) return true;
    q.pop();
    for(int i = 0 ; i < 4; i ++)
    {
      int gox = curx+dx[i], goy = cury+dy[i];
 
      if(valid(gox,goy) && !vis[gox][goy] && arr[gox][goy]!=-1){
        if(mins+((arr[curx][cury])/o)+1 < arr[gox][goy]){
 
          vis[gox][goy]=1;
          arr[gox][goy]=arr[curx][cury]+1;
          q.push({gox,goy});
        }
      }
    }
  }
 
 
  return false;
}
int32_t main()
{
  //freopen("abc.in", "r", stdin);
  cin >> n >> o;
  int id[n][n];
  for(int i = 0 ; i < n ; i ++){
    for(int j = 0 ; j < n ; j ++){
      char x; cin >> x;
      ar[i][j] = (x=='H'?1:((x=='G'||x=='D'||x=='M')?0:-1));
      if(x=='M') srcx=i, srcy=j;
      if(x=='D') destx=i, desty=j;
    }
  }
  int l = 0 , r = n*n;
  int ans=-1;
  while(l <= r)
  {
    int mid = (l+r)/2;
    if(check(mid))
    {
      l = mid+1;
      ans=mid;
    }
    else
    {
      r = mid-1;
    }
  }
  cout<<ans<<endl;
}

Compilation message

mecho.cpp: In function 'int32_t main()':
mecho.cpp:86:7: warning: unused variable 'id' [-Wunused-variable]
   86 |   int id[n][n];
      |       ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 340 KB Output isn't correct
7 Incorrect 454 ms 15548 KB Output isn't correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Incorrect 1 ms 596 KB Output isn't correct
13 Incorrect 2 ms 576 KB Output isn't correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 596 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 2 ms 596 KB Output is correct
28 Correct 2 ms 596 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 2 ms 596 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 2 ms 724 KB Output is correct
33 Correct 34 ms 4292 KB Output is correct
34 Correct 46 ms 4308 KB Output is correct
35 Correct 71 ms 4312 KB Output is correct
36 Correct 49 ms 5292 KB Output is correct
37 Correct 47 ms 5204 KB Output is correct
38 Correct 80 ms 5304 KB Output is correct
39 Correct 57 ms 6228 KB Output is correct
40 Correct 59 ms 6264 KB Output is correct
41 Correct 106 ms 6284 KB Output is correct
42 Correct 75 ms 7332 KB Output is correct
43 Correct 88 ms 7260 KB Output is correct
44 Correct 142 ms 7360 KB Output is correct
45 Correct 92 ms 8464 KB Output is correct
46 Correct 95 ms 8460 KB Output is correct
47 Correct 183 ms 8412 KB Output is correct
48 Correct 128 ms 9572 KB Output is correct
49 Correct 124 ms 9720 KB Output is correct
50 Correct 263 ms 9616 KB Output is correct
51 Correct 139 ms 10968 KB Output is correct
52 Correct 135 ms 10964 KB Output is correct
53 Correct 257 ms 10852 KB Output is correct
54 Correct 163 ms 12336 KB Output is correct
55 Correct 171 ms 12344 KB Output is correct
56 Correct 355 ms 12372 KB Output is correct
57 Correct 181 ms 13832 KB Output is correct
58 Correct 189 ms 13788 KB Output is correct
59 Correct 451 ms 13804 KB Output is correct
60 Correct 219 ms 15264 KB Output is correct
61 Correct 209 ms 15328 KB Output is correct
62 Correct 487 ms 15324 KB Output is correct
63 Correct 514 ms 15336 KB Output is correct
64 Correct 596 ms 15396 KB Output is correct
65 Correct 544 ms 15328 KB Output is correct
66 Correct 518 ms 15444 KB Output is correct
67 Correct 520 ms 15340 KB Output is correct
68 Correct 538 ms 15308 KB Output is correct
69 Correct 544 ms 15388 KB Output is correct
70 Correct 568 ms 15420 KB Output is correct
71 Correct 561 ms 15436 KB Output is correct
72 Incorrect 516 ms 15384 KB Output isn't correct
73 Incorrect 513 ms 15892 KB Output isn't correct
74 Correct 565 ms 16324 KB Output is correct
75 Correct 599 ms 15936 KB Output is correct
76 Correct 538 ms 15940 KB Output is correct
77 Correct 546 ms 15932 KB Output is correct
78 Correct 511 ms 15852 KB Output is correct
79 Correct 502 ms 15852 KB Output is correct
80 Correct 468 ms 15964 KB Output is correct
81 Correct 466 ms 15960 KB Output is correct
82 Correct 492 ms 15976 KB Output is correct
83 Correct 484 ms 15776 KB Output is correct
84 Correct 467 ms 15768 KB Output is correct
85 Correct 493 ms 15876 KB Output is correct
86 Correct 505 ms 15884 KB Output is correct
87 Correct 493 ms 15756 KB Output is correct
88 Correct 460 ms 15596 KB Output is correct
89 Correct 473 ms 15800 KB Output is correct
90 Correct 455 ms 15596 KB Output is correct
91 Correct 494 ms 15820 KB Output is correct
92 Correct 507 ms 15728 KB Output is correct