Submission #583407

# Submission time Handle Problem Language Result Execution time Memory
583407 2022-06-25T10:28:49 Z HeyYouNotYouYou Mecho (IOI09_mecho) C++14
30 / 100
745 ms 21716 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],arr2[n][n];
  for(int i = 0 ; i < n ; i ++)
    for(int j = 0 ; j < n ; j ++)
      {
        arr[i][j]=ar[i][j]; arr2[i][j]=1;
        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});
      }
    }
  }
 
 queue<pair<pair<int,int>,int>>qq;
  memset(vis,0,sizeof vis);
  qq.push({{srcx,srcy},0});
  vis[srcx][srcy]=1;
  if(arr[srcx][srcy]<=mins) return false;
  arr[srcx][srcy]=1;
  while(!qq.empty()){
    int curx=qq.front().first.first;
    int cury=qq.front().first.second;
    int c = qq.front().second;
    if(curx==destx&&cury==desty) return true;
    qq.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+arr2[curx][cury]+(c%o==0&&c>0) < arr[gox][goy]){
          vis[gox][goy]=1;
          if(c%o!=0||!c)
          arr2[gox][goy]=arr2[curx][cury];
          else
          arr2[gox][goy]=arr2[curx][cury]+1;
          qq.push({{gox,goy},c+1});
        }
      }
    }
  }
 
 
  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:91:7: warning: unused variable 'id' [-Wunused-variable]
   91 |   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 212 KB Output isn't correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Incorrect 494 ms 21328 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 596 KB Output isn't correct
13 Incorrect 3 ms 564 KB Output isn't correct
14 Correct 3 ms 596 KB Output is correct
15 Incorrect 1 ms 308 KB Output isn't correct
16 Correct 1 ms 340 KB Output is correct
17 Incorrect 1 ms 340 KB Output isn't correct
18 Correct 1 ms 340 KB Output is correct
19 Incorrect 1 ms 436 KB Output isn't correct
20 Correct 1 ms 340 KB Output is correct
21 Incorrect 1 ms 432 KB Output isn't correct
22 Correct 2 ms 436 KB Output is correct
23 Incorrect 1 ms 596 KB Output isn't correct
24 Correct 1 ms 468 KB Output is correct
25 Incorrect 2 ms 652 KB Output isn't correct
26 Correct 2 ms 596 KB Output is correct
27 Incorrect 2 ms 696 KB Output isn't correct
28 Correct 2 ms 596 KB Output is correct
29 Incorrect 2 ms 724 KB Output isn't correct
30 Correct 2 ms 724 KB Output is correct
31 Incorrect 2 ms 696 KB Output isn't correct
32 Correct 2 ms 724 KB Output is correct
33 Incorrect 33 ms 5476 KB Output isn't correct
34 Correct 39 ms 5484 KB Output is correct
35 Correct 70 ms 5580 KB Output is correct
36 Incorrect 57 ms 6704 KB Output isn't correct
37 Correct 63 ms 6708 KB Output is correct
38 Correct 98 ms 6844 KB Output is correct
39 Incorrect 71 ms 8052 KB Output isn't correct
40 Correct 69 ms 8060 KB Output is correct
41 Correct 132 ms 8196 KB Output is correct
42 Incorrect 85 ms 9528 KB Output isn't correct
43 Correct 99 ms 9660 KB Output is correct
44 Correct 166 ms 9548 KB Output is correct
45 Incorrect 111 ms 11128 KB Output isn't correct
46 Correct 103 ms 11036 KB Output is correct
47 Correct 221 ms 11148 KB Output is correct
48 Incorrect 137 ms 12852 KB Output isn't correct
49 Correct 125 ms 12820 KB Output is correct
50 Correct 244 ms 12880 KB Output is correct
51 Incorrect 165 ms 14668 KB Output isn't correct
52 Correct 169 ms 14772 KB Output is correct
53 Correct 331 ms 14764 KB Output is correct
54 Incorrect 185 ms 16588 KB Output isn't correct
55 Correct 202 ms 16660 KB Output is correct
56 Correct 399 ms 16680 KB Output is correct
57 Incorrect 212 ms 18736 KB Output isn't correct
58 Correct 218 ms 18744 KB Output is correct
59 Correct 432 ms 18880 KB Output is correct
60 Incorrect 232 ms 20948 KB Output isn't correct
61 Correct 270 ms 20952 KB Output is correct
62 Correct 517 ms 20976 KB Output is correct
63 Correct 571 ms 20940 KB Output is correct
64 Correct 639 ms 20984 KB Output is correct
65 Correct 639 ms 20984 KB Output is correct
66 Incorrect 643 ms 20980 KB Output isn't correct
67 Correct 535 ms 20976 KB Output is correct
68 Correct 580 ms 21032 KB Output is correct
69 Correct 601 ms 21016 KB Output is correct
70 Correct 576 ms 21148 KB Output is correct
71 Correct 616 ms 21100 KB Output is correct
72 Incorrect 558 ms 21028 KB Output isn't correct
73 Incorrect 638 ms 21572 KB Output isn't correct
74 Correct 610 ms 21608 KB Output is correct
75 Correct 666 ms 21716 KB Output is correct
76 Correct 745 ms 21564 KB Output is correct
77 Correct 723 ms 21652 KB Output is correct
78 Correct 543 ms 21496 KB Output is correct
79 Correct 569 ms 21480 KB Output is correct
80 Correct 565 ms 21496 KB Output is correct
81 Correct 561 ms 21500 KB Output is correct
82 Correct 508 ms 21492 KB Output is correct
83 Correct 580 ms 21444 KB Output is correct
84 Correct 553 ms 21528 KB Output is correct
85 Correct 582 ms 21460 KB Output is correct
86 Correct 574 ms 21424 KB Output is correct
87 Correct 595 ms 21528 KB Output is correct
88 Correct 483 ms 21304 KB Output is correct
89 Correct 572 ms 21196 KB Output is correct
90 Correct 540 ms 21296 KB Output is correct
91 Correct 538 ms 21300 KB Output is correct
92 Correct 587 ms 21196 KB Output is correct