Submission #1118604

# Submission time Handle Problem Language Result Execution time Memory
1118604 2024-11-25T21:18:47 Z ojoConmigo Mecho (IOI09_mecho) C++17
43 / 100
208 ms 6212 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define D(x) cout << #x << ':' << ' ' << x << endl;
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

typedef long long ll;
typedef long double ld;

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

enum {
    T=-4,G,M,D,H=0
};

const int MX = 801;
const int sx[] = {0,1,-1,0};
const int sy[] = {1,0,0,-1};
int n,s;
pii ini, fin;
int bee[MX][MX];
//int steps[MX][MX];
int max_min = 0;

bool valid(int x){
    return 0 <= x && x < n;
}

bool valid(int x, int y){
    return valid(x) && valid(y);
}

void bfs(vector<pii> & hives){
    queue<pii> q;
    for(auto h : hives) q.push(h);
    while(!q.empty()){
        auto [x,y] = q.front();
        q.pop();
        for(int i=0;i<4;++i){
            int nx = x+sx[i];
            int ny = y+sy[i];
            if(valid(nx,ny) && bee[nx][ny] == G){
                bee[nx][ny] = bee[x][y]+1;
                max_min = max(max_min,bee[nx][ny]);
                q.push({nx,ny});
            }
        }
    }
}
/*
void step(){
    queue<pii> q;
    q.push(ini);
    steps[ini.first][ini.second] = -1;
    while(!q.empty()){
        auto [x,y] = q.front();
        q.pop();
        for(int i=0;i<4;++i){
            int nx = x+sx[i];
            int ny = y+sy[i];
            if(valid(nx,ny) && steps[nx][ny] == -1 && (bee[nx][ny] > 0 || bee[nx][ny] == D)){
                steps[nx][ny] = steps[x][y]+1;
                q.push({nx,ny});
            }
        }
    }
}

bool mecho(int ini_minute){
    vector<vector<bool>> vis(n,vector<bool>(n,false));
    queue<pii> q;
    q.push(ini);
    vis[ini.first][ini.second] = true;
    while(!q.empty()){
        auto [x,y] = q.front();
        q.pop();
        for(int i=0;i<4;++i){
            int nx = x+sx[i];
            int ny = y+sy[i];
            if(valid(nx,ny) && !vis[nx][ny]){
                vis[nx][ny] = true;
                if(bee[nx][ny] == D)return true;
                if(bee[nx][ny] > ini_minute+((steps[nx][ny])/s))
                    q.push({nx,ny});
            }
        }
    }
    return false;
}
*/

bool mecho(int ini_minute){
    //vector<vector<bool>> vis(n,vector<bool>(n,false));
    vvi steps(n,vi(n,-1));
    queue<pii> q;
    q.push(ini);
    //vis[ini.first][ini.second] = true;
    steps[ini.first][ini.second] = 0;
    while(!q.empty()){
        auto [x,y] = q.front();
        q.pop();
        for(int i=0;i<4;++i){
            int nx = x+sx[i];
            int ny = y+sy[i];
            if(valid(nx,ny) && steps[nx][ny] == -1){
                if(bee[nx][ny] == D)return true;
                if(bee[nx][ny] > ini_minute+((steps[x][y])/s)){
                    //D(nx)D(ny)
                    steps[nx][ny] = steps[x][y]+1;
                    q.push({nx,ny});
                }
                    
            }
        }
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> s;
    vector<pii> hives;
    for(int i = 0; i < n; ++i){
        for(int j=0; j<n; ++j){
            char c; cin >> c;
            switch (c)
            {
            case 'T':
                bee[i][j] = T;    
                break;
            case 'M':
                ini = {i,j};
                bee[i][j] = M;  
                break;
            case 'D':
                fin = {i,j};
                bee[i][j] = D;
                break;
            case 'G':
                bee[i][j] = G;  
                break;
            case 'H':
                hives.emplace_back(i,j);
                bee[i][j] = H;
                break;
            }
            //steps[i][j] = -1;
        }
    }

    bfs(hives);
    //step();
    /*cout << "bees\n";
    for(int i = 0; i < n; ++i){
        for(int j=0;j<n;++j){
            cout << bee[i][j] << ' ';
        }
        cout << endl;
    }
    cout << "steps\n";
    for(int i = 0; i < n; ++i){
        for(int j=0;j<n;++j){
            cout << steps[i][j] << ' ';
        }
        cout << endl;
    }*/
    int lo = 0,hi = max_min,ans=-1,mid;
    while(lo <= hi){
        mid = (lo+hi)/2;
        if(mecho(mid)){
            ans = mid;
            lo = mid+1;
        }else{
            hi = mid-1;
        }
    }

    cout << ans << endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 484 KB Output isn't correct
2 Incorrect 1 ms 504 KB Output isn't correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 69 ms 6196 KB Output is correct
8 Incorrect 1 ms 348 KB Output isn't correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 2652 KB Output is correct
13 Incorrect 1 ms 480 KB Output isn't correct
14 Correct 1 ms 2652 KB Output is correct
15 Incorrect 1 ms 348 KB Output isn't correct
16 Correct 1 ms 348 KB Output is correct
17 Incorrect 1 ms 348 KB Output isn't correct
18 Correct 1 ms 488 KB Output is correct
19 Incorrect 1 ms 336 KB Output isn't correct
20 Correct 1 ms 336 KB Output is correct
21 Incorrect 2 ms 592 KB Output isn't correct
22 Correct 1 ms 592 KB Output is correct
23 Incorrect 1 ms 592 KB Output isn't correct
24 Correct 1 ms 592 KB Output is correct
25 Incorrect 1 ms 604 KB Output isn't correct
26 Correct 2 ms 604 KB Output is correct
27 Incorrect 2 ms 760 KB Output isn't correct
28 Correct 1 ms 592 KB Output is correct
29 Incorrect 1 ms 592 KB Output isn't correct
30 Correct 1 ms 472 KB Output is correct
31 Incorrect 1 ms 728 KB Output isn't correct
32 Correct 1 ms 604 KB Output is correct
33 Incorrect 8 ms 2192 KB Output isn't correct
34 Correct 7 ms 2180 KB Output is correct
35 Correct 18 ms 2180 KB Output is correct
36 Incorrect 12 ms 2528 KB Output isn't correct
37 Correct 12 ms 2396 KB Output is correct
38 Correct 23 ms 2388 KB Output is correct
39 Incorrect 14 ms 2936 KB Output isn't correct
40 Correct 16 ms 2848 KB Output is correct
41 Correct 31 ms 2888 KB Output is correct
42 Incorrect 19 ms 4000 KB Output isn't correct
43 Correct 15 ms 3940 KB Output is correct
44 Correct 41 ms 3932 KB Output is correct
45 Incorrect 22 ms 4264 KB Output isn't correct
46 Correct 24 ms 4352 KB Output is correct
47 Correct 47 ms 3728 KB Output is correct
48 Incorrect 24 ms 4168 KB Output isn't correct
49 Correct 22 ms 4140 KB Output is correct
50 Correct 55 ms 4128 KB Output is correct
51 Incorrect 31 ms 4604 KB Output isn't correct
52 Correct 32 ms 4616 KB Output is correct
53 Correct 68 ms 4612 KB Output is correct
54 Incorrect 48 ms 5156 KB Output isn't correct
55 Correct 33 ms 5096 KB Output is correct
56 Correct 91 ms 5132 KB Output is correct
57 Incorrect 38 ms 5608 KB Output isn't correct
58 Correct 48 ms 5620 KB Output is correct
59 Correct 113 ms 5572 KB Output is correct
60 Incorrect 46 ms 6192 KB Output isn't correct
61 Correct 36 ms 6212 KB Output is correct
62 Correct 93 ms 6152 KB Output is correct
63 Correct 104 ms 6164 KB Output is correct
64 Correct 189 ms 6148 KB Output is correct
65 Correct 208 ms 6136 KB Output is correct
66 Incorrect 127 ms 6136 KB Output isn't correct
67 Correct 135 ms 6160 KB Output is correct
68 Correct 57 ms 6176 KB Output is correct
69 Correct 46 ms 6148 KB Output is correct
70 Correct 51 ms 6172 KB Output is correct
71 Correct 49 ms 6172 KB Output is correct
72 Incorrect 67 ms 6160 KB Output isn't correct
73 Incorrect 62 ms 6160 KB Output isn't correct
74 Correct 66 ms 6128 KB Output is correct
75 Correct 62 ms 6172 KB Output is correct
76 Correct 68 ms 6192 KB Output is correct
77 Correct 74 ms 6148 KB Output is correct
78 Correct 72 ms 6192 KB Output is correct
79 Correct 58 ms 6172 KB Output is correct
80 Correct 62 ms 6172 KB Output is correct
81 Correct 85 ms 6180 KB Output is correct
82 Correct 61 ms 6176 KB Output is correct
83 Correct 75 ms 6116 KB Output is correct
84 Correct 73 ms 6196 KB Output is correct
85 Correct 58 ms 6088 KB Output is correct
86 Correct 70 ms 6172 KB Output is correct
87 Correct 64 ms 6156 KB Output is correct
88 Correct 76 ms 5984 KB Output is correct
89 Correct 63 ms 6168 KB Output is correct
90 Correct 67 ms 6196 KB Output is correct
91 Correct 73 ms 6132 KB Output is correct
92 Correct 72 ms 6152 KB Output is correct