Submission #558324

# Submission time Handle Problem Language Result Execution time Memory
558324 2022-05-07T06:02:21 Z Cookie Mecho (IOI09_mecho) C++14
22 / 100
206 ms 6884 KB
#include <bits/stdc++.h>
using namespace std;
#define LIFESUCKS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ld long double
#define ar array
#include<cstdio>
#define vt vector
#include<fstream>
ifstream fin("piggyback.in");
ofstream fout("piggyback.out");
#include<fstream>
#define pb push_back
#define all(c) (c).begin(), (c).end()

#define fi first
#define se second
#define vt vector
using namespace std;
int n, s, sti, stj, eni, enj;
bool vis[801][801];
int dis[801][801];
int dis2[801][801];
char a[801][801];
bool bee = true;
const int x[4] = {1, -1, 0, 0};
const int y[4] = {0, 0, 1, -1};
bool check(int mid){
    memset(vis, false, sizeof(vis));
    memset(dis2, false, sizeof(dis2));
    queue<pair<int, int>>q;
    q.push({sti, stj});
    vis[sti][stj] = true;
    dis2[sti][stj] = 0;
    while(!q.empty()){
        auto now = q.front(); q.pop();
        //cout << "mm";
        for(int i = 0; i < 4; i++){
            int cri = now.fi + x[i];
            int crj = now.se + y[i];
            if(cri < 0 || crj < 0 || cri >= n || crj >= n)continue;
            if(!vis[cri][crj] &&(a[cri][crj] == 'G' || a[cri][crj] == 'D')){
               // cout << "lol";
                if(dis[cri][crj] > ceil((double)(dis2[now.fi][now.se] + 1) / (double)s) + mid){
                    vis[cri][crj] = true;
                    dis2[cri][crj] = dis2[now.fi][now.se] + 1;
                    if(a[cri][crj] == 'D')return(true);
                    q.push({cri, crj});
                }
            }
        }
    }
    //cout << "\n";
    return(false);
}
void bfs(){
    memset(vis, false, sizeof(vis));
    
    queue<pair<int, int>>q;
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(a[i][j] == 'H'){
                q.push({i, j});
                vis[i][j] = true;
                dis[i][j] = 0;
            }
        }
    }
    while(!q.empty()){
        
        auto now = q.front(); q.pop();
        for(int i = 0; i < 4; i++){
            int cri = now.fi + x[i];
            int crj = now.se + y[i];
            if(cri < 0 || crj < 0 || cri >= n || crj >= n)continue;
            if(!vis[cri][crj] && (a[cri][crj] == 'G' || a[cri][crj] == 'M')){
                vis[cri][crj] = true;
                dis[cri][crj] = dis[now.fi][now.se] + 1;
                q.push({cri, crj});
            }
        }
    }
    
}
int main(){
    LIFESUCKS;
   cin >> n >> s;
   
   for(int i = 0; i < n; i++){
       for(int j = 0; j < n; j++){
           dis[i][j] = 1e9;
           cin >> a[i][j];
           if(a[i][j] == 'M'){
               sti = i, stj = j;
           }if(a[i][j] == 'D'){
               eni = i; enj = j;
           }
       }
   }
   //cout << sti << ' ' << stj << " ";
   bfs();
   
   int l = 0;
   int r = 64000;
   int ans = -1;
   while(l <= r){
       int mid = l + (r - l) / 2;
       if(check(mid)){
           ans = mid; l = mid + 1;
       }else{
           r = mid - 1;
       }
   }
   cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3412 KB Output is correct
2 Correct 3 ms 3412 KB Output is correct
3 Correct 3 ms 3412 KB Output is correct
4 Correct 3 ms 3412 KB Output is correct
5 Incorrect 3 ms 3504 KB Output isn't correct
6 Incorrect 3 ms 3412 KB Output isn't correct
7 Incorrect 95 ms 6704 KB Output isn't correct
8 Correct 3 ms 3412 KB Output is correct
9 Incorrect 3 ms 3412 KB Output isn't correct
10 Incorrect 3 ms 3496 KB Output isn't correct
11 Incorrect 3 ms 3412 KB Output isn't correct
12 Incorrect 3 ms 3668 KB Output isn't correct
13 Correct 3 ms 3668 KB Output is correct
14 Correct 3 ms 3668 KB Output is correct
15 Correct 3 ms 3540 KB Output is correct
16 Incorrect 4 ms 3540 KB Output isn't correct
17 Correct 4 ms 3540 KB Output is correct
18 Incorrect 3 ms 3540 KB Output isn't correct
19 Correct 3 ms 3540 KB Output is correct
20 Incorrect 4 ms 3540 KB Output isn't correct
21 Correct 3 ms 3540 KB Output is correct
22 Incorrect 3 ms 3632 KB Output isn't correct
23 Correct 3 ms 3540 KB Output is correct
24 Incorrect 3 ms 3668 KB Output isn't correct
25 Correct 3 ms 3668 KB Output is correct
26 Incorrect 3 ms 3668 KB Output isn't correct
27 Correct 3 ms 3668 KB Output is correct
28 Incorrect 3 ms 3668 KB Output isn't correct
29 Correct 3 ms 3668 KB Output is correct
30 Incorrect 3 ms 3748 KB Output isn't correct
31 Correct 3 ms 3668 KB Output is correct
32 Incorrect 3 ms 3668 KB Output isn't correct
33 Correct 7 ms 4820 KB Output is correct
34 Incorrect 9 ms 4848 KB Output isn't correct
35 Incorrect 33 ms 4824 KB Output isn't correct
36 Incorrect 8 ms 5044 KB Output isn't correct
37 Incorrect 7 ms 4948 KB Output isn't correct
38 Incorrect 29 ms 5036 KB Output isn't correct
39 Incorrect 8 ms 5240 KB Output isn't correct
40 Incorrect 9 ms 5200 KB Output isn't correct
41 Incorrect 39 ms 5176 KB Output isn't correct
42 Incorrect 10 ms 5408 KB Output isn't correct
43 Incorrect 10 ms 5432 KB Output isn't correct
44 Incorrect 47 ms 5332 KB Output isn't correct
45 Incorrect 11 ms 5588 KB Output isn't correct
46 Incorrect 16 ms 5588 KB Output isn't correct
47 Incorrect 90 ms 5616 KB Output isn't correct
48 Incorrect 16 ms 5748 KB Output isn't correct
49 Incorrect 14 ms 5716 KB Output isn't correct
50 Incorrect 67 ms 5812 KB Output isn't correct
51 Incorrect 14 ms 5972 KB Output isn't correct
52 Incorrect 15 ms 5944 KB Output isn't correct
53 Incorrect 80 ms 6004 KB Output isn't correct
54 Incorrect 18 ms 6144 KB Output isn't correct
55 Incorrect 18 ms 6192 KB Output isn't correct
56 Incorrect 112 ms 6208 KB Output isn't correct
57 Incorrect 17 ms 6348 KB Output isn't correct
58 Incorrect 20 ms 6356 KB Output isn't correct
59 Incorrect 111 ms 6400 KB Output isn't correct
60 Incorrect 22 ms 6608 KB Output isn't correct
61 Incorrect 20 ms 6584 KB Output isn't correct
62 Incorrect 127 ms 6596 KB Output isn't correct
63 Incorrect 107 ms 6596 KB Output isn't correct
64 Incorrect 206 ms 6592 KB Output isn't correct
65 Incorrect 163 ms 6600 KB Output isn't correct
66 Correct 140 ms 6664 KB Output is correct
67 Correct 105 ms 6572 KB Output is correct
68 Incorrect 53 ms 6604 KB Output isn't correct
69 Incorrect 55 ms 6612 KB Output isn't correct
70 Incorrect 43 ms 6560 KB Output isn't correct
71 Incorrect 33 ms 6572 KB Output isn't correct
72 Correct 31 ms 6500 KB Output is correct
73 Correct 41 ms 6884 KB Output is correct
74 Incorrect 65 ms 6868 KB Output isn't correct
75 Incorrect 76 ms 6804 KB Output isn't correct
76 Incorrect 62 ms 6868 KB Output isn't correct
77 Incorrect 65 ms 6868 KB Output isn't correct
78 Correct 75 ms 6780 KB Output is correct
79 Incorrect 56 ms 6780 KB Output isn't correct
80 Incorrect 90 ms 6844 KB Output isn't correct
81 Incorrect 86 ms 6796 KB Output isn't correct
82 Incorrect 65 ms 6856 KB Output isn't correct
83 Incorrect 75 ms 6808 KB Output isn't correct
84 Incorrect 76 ms 6740 KB Output isn't correct
85 Incorrect 90 ms 6804 KB Output isn't correct
86 Incorrect 96 ms 6740 KB Output isn't correct
87 Incorrect 74 ms 6760 KB Output isn't correct
88 Incorrect 76 ms 6652 KB Output isn't correct
89 Incorrect 86 ms 6756 KB Output isn't correct
90 Incorrect 88 ms 6736 KB Output isn't correct
91 Incorrect 103 ms 6680 KB Output isn't correct
92 Incorrect 80 ms 6748 KB Output isn't correct