Submission #583149

# Submission time Handle Problem Language Result Execution time Memory
583149 2022-06-24T22:31:11 Z HeyYouNotYouYou Mecho (IOI09_mecho) C++14
30 / 100
625 ms 16740 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;
  arr[srcx][srcy]=0;
  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(curx==srcx&&cury==srcy){
          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});
          }
        }
        else 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:92:7: warning: unused variable 'id' [-Wunused-variable]
   92 |   int id[n][n];
      |       ^~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Incorrect 1 ms 304 KB Output isn't correct
5 Correct 0 ms 340 KB Output is correct
6 Incorrect 1 ms 308 KB Output isn't correct
7 Incorrect 604 ms 16188 KB Output isn't correct
8 Incorrect 1 ms 340 KB Output isn't 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 2 ms 516 KB Output isn't correct
13 Incorrect 2 ms 596 KB Output isn't correct
14 Correct 2 ms 564 KB Output is correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Correct 1 ms 340 KB Output is correct
17 Incorrect 1 ms 312 KB Output isn't correct
18 Correct 1 ms 340 KB Output is correct
19 Incorrect 1 ms 340 KB Output isn't correct
20 Correct 1 ms 432 KB Output is correct
21 Incorrect 1 ms 468 KB Output isn't correct
22 Correct 1 ms 468 KB Output is correct
23 Incorrect 2 ms 468 KB Output isn't correct
24 Correct 1 ms 564 KB Output is correct
25 Incorrect 1 ms 596 KB Output isn't correct
26 Correct 2 ms 596 KB Output is correct
27 Incorrect 1 ms 596 KB Output isn't correct
28 Correct 2 ms 596 KB Output is correct
29 Incorrect 2 ms 596 KB Output isn't correct
30 Correct 2 ms 596 KB Output is correct
31 Incorrect 2 ms 724 KB Output isn't correct
32 Correct 2 ms 724 KB Output is correct
33 Incorrect 37 ms 4476 KB Output isn't correct
34 Correct 37 ms 4508 KB Output is correct
35 Correct 65 ms 4520 KB Output is correct
36 Incorrect 46 ms 5444 KB Output isn't correct
37 Correct 47 ms 5460 KB Output is correct
38 Correct 81 ms 5460 KB Output is correct
39 Incorrect 70 ms 6484 KB Output isn't correct
40 Correct 66 ms 6488 KB Output is correct
41 Correct 108 ms 6412 KB Output is correct
42 Incorrect 72 ms 7580 KB Output isn't correct
43 Correct 77 ms 7644 KB Output is correct
44 Correct 152 ms 7592 KB Output is correct
45 Incorrect 98 ms 8736 KB Output isn't correct
46 Correct 94 ms 8756 KB Output is correct
47 Correct 184 ms 8768 KB Output is correct
48 Incorrect 120 ms 9984 KB Output isn't correct
49 Correct 117 ms 10068 KB Output is correct
50 Correct 202 ms 10052 KB Output is correct
51 Incorrect 143 ms 11384 KB Output isn't correct
52 Correct 134 ms 11336 KB Output is correct
53 Correct 293 ms 11396 KB Output is correct
54 Incorrect 159 ms 12816 KB Output isn't correct
55 Correct 162 ms 12820 KB Output is correct
56 Correct 331 ms 12832 KB Output is correct
57 Incorrect 179 ms 14336 KB Output isn't correct
58 Correct 186 ms 14384 KB Output is correct
59 Correct 452 ms 14412 KB Output is correct
60 Incorrect 212 ms 16000 KB Output isn't correct
61 Correct 217 ms 16016 KB Output is correct
62 Correct 512 ms 15924 KB Output is correct
63 Correct 511 ms 15964 KB Output is correct
64 Correct 625 ms 15960 KB Output is correct
65 Correct 540 ms 16084 KB Output is correct
66 Incorrect 560 ms 16204 KB Output isn't correct
67 Correct 520 ms 15964 KB Output is correct
68 Correct 520 ms 15948 KB Output is correct
69 Correct 545 ms 16136 KB Output is correct
70 Correct 522 ms 16004 KB Output is correct
71 Correct 532 ms 15944 KB Output is correct
72 Incorrect 528 ms 16012 KB Output isn't correct
73 Incorrect 505 ms 16564 KB Output isn't correct
74 Correct 575 ms 16672 KB Output is correct
75 Correct 613 ms 16568 KB Output is correct
76 Correct 562 ms 16740 KB Output is correct
77 Correct 554 ms 16572 KB Output is correct
78 Correct 540 ms 16716 KB Output is correct
79 Correct 492 ms 16480 KB Output is correct
80 Correct 507 ms 16472 KB Output is correct
81 Correct 528 ms 16676 KB Output is correct
82 Correct 472 ms 16476 KB Output is correct
83 Correct 496 ms 16484 KB Output is correct
84 Correct 513 ms 16408 KB Output is correct
85 Correct 506 ms 16500 KB Output is correct
86 Correct 491 ms 16492 KB Output is correct
87 Correct 491 ms 16444 KB Output is correct
88 Correct 491 ms 16292 KB Output is correct
89 Correct 490 ms 16288 KB Output is correct
90 Correct 491 ms 16288 KB Output is correct
91 Correct 475 ms 16288 KB Output is correct
92 Correct 511 ms 16284 KB Output is correct