Submission #558323

# Submission time Handle Problem Language Result Execution time Memory
558323 2022-05-07T05:59:40 Z Cookie Mecho (IOI09_mecho) C++14
29 / 100
175 ms 7124 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 + 1;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3412 KB Output isn't correct
2 Incorrect 3 ms 3412 KB Output isn't correct
3 Incorrect 3 ms 3412 KB Output isn't correct
4 Incorrect 3 ms 3412 KB Output isn't correct
5 Correct 3 ms 3408 KB Output is correct
6 Correct 3 ms 3412 KB Output is correct
7 Correct 85 ms 6964 KB Output is correct
8 Incorrect 3 ms 3412 KB Output isn't correct
9 Correct 3 ms 3412 KB Output is correct
10 Correct 3 ms 3408 KB Output is correct
11 Correct 3 ms 3412 KB Output is correct
12 Incorrect 3 ms 3672 KB Output isn't correct
13 Incorrect 3 ms 3668 KB Output isn't correct
14 Incorrect 4 ms 3672 KB Output isn't correct
15 Incorrect 3 ms 3540 KB Output isn't correct
16 Correct 3 ms 3540 KB Output is correct
17 Incorrect 3 ms 3540 KB Output isn't correct
18 Correct 5 ms 3540 KB Output is correct
19 Incorrect 5 ms 3536 KB Output isn't correct
20 Correct 4 ms 3540 KB Output is correct
21 Incorrect 3 ms 3540 KB Output isn't correct
22 Correct 3 ms 3592 KB Output is correct
23 Incorrect 3 ms 3668 KB Output isn't correct
24 Correct 3 ms 3660 KB Output is correct
25 Incorrect 3 ms 3668 KB Output isn't correct
26 Correct 3 ms 3668 KB Output is correct
27 Incorrect 3 ms 3668 KB Output isn't correct
28 Correct 3 ms 3796 KB Output is correct
29 Incorrect 3 ms 3676 KB Output isn't correct
30 Correct 4 ms 3760 KB Output is correct
31 Incorrect 4 ms 3668 KB Output isn't correct
32 Correct 3 ms 3668 KB Output is correct
33 Incorrect 7 ms 4960 KB Output isn't correct
34 Correct 7 ms 4948 KB Output is correct
35 Correct 27 ms 4956 KB Output is correct
36 Incorrect 7 ms 5204 KB Output isn't correct
37 Correct 8 ms 5204 KB Output is correct
38 Correct 30 ms 5080 KB Output is correct
39 Incorrect 8 ms 5332 KB Output isn't correct
40 Correct 10 ms 5316 KB Output is correct
41 Correct 39 ms 5428 KB Output is correct
42 Incorrect 10 ms 5620 KB Output isn't correct
43 Correct 12 ms 5596 KB Output is correct
44 Correct 50 ms 5608 KB Output is correct
45 Incorrect 12 ms 5844 KB Output isn't correct
46 Incorrect 13 ms 5844 KB Output isn't correct
47 Correct 57 ms 5872 KB Output is correct
48 Incorrect 13 ms 5972 KB Output isn't correct
49 Incorrect 13 ms 5984 KB Output isn't correct
50 Correct 65 ms 5976 KB Output is correct
51 Incorrect 14 ms 6228 KB Output isn't correct
52 Incorrect 15 ms 6208 KB Output isn't correct
53 Correct 98 ms 6320 KB Output is correct
54 Incorrect 17 ms 6360 KB Output isn't correct
55 Incorrect 17 ms 6404 KB Output isn't correct
56 Correct 93 ms 6356 KB Output is correct
57 Incorrect 19 ms 6600 KB Output isn't correct
58 Incorrect 19 ms 6568 KB Output isn't correct
59 Correct 121 ms 6648 KB Output is correct
60 Incorrect 21 ms 6820 KB Output isn't correct
61 Incorrect 22 ms 6740 KB Output isn't correct
62 Correct 122 ms 6828 KB Output is correct
63 Correct 89 ms 6784 KB Output is correct
64 Correct 175 ms 6848 KB Output is correct
65 Correct 157 ms 6852 KB Output is correct
66 Incorrect 133 ms 6732 KB Output isn't correct
67 Incorrect 106 ms 6740 KB Output isn't correct
68 Correct 45 ms 6788 KB Output is correct
69 Correct 48 ms 6764 KB Output is correct
70 Correct 41 ms 6868 KB Output is correct
71 Correct 34 ms 6860 KB Output is correct
72 Incorrect 32 ms 6860 KB Output isn't correct
73 Incorrect 38 ms 7036 KB Output isn't correct
74 Correct 60 ms 7124 KB Output is correct
75 Correct 66 ms 7124 KB Output is correct
76 Correct 61 ms 7052 KB Output is correct
77 Correct 67 ms 7064 KB Output is correct
78 Incorrect 72 ms 7088 KB Output isn't correct
79 Correct 53 ms 7040 KB Output is correct
80 Correct 62 ms 7096 KB Output is correct
81 Correct 70 ms 7044 KB Output is correct
82 Correct 64 ms 7028 KB Output is correct
83 Correct 71 ms 6992 KB Output is correct
84 Correct 74 ms 7112 KB Output is correct
85 Correct 70 ms 6988 KB Output is correct
86 Correct 75 ms 7056 KB Output is correct
87 Correct 73 ms 7064 KB Output is correct
88 Correct 71 ms 6992 KB Output is correct
89 Correct 81 ms 7008 KB Output is correct
90 Correct 90 ms 7060 KB Output is correct
91 Correct 85 ms 6936 KB Output is correct
92 Correct 83 ms 6896 KB Output is correct