Submission #1100010

# Submission time Handle Problem Language Result Execution time Memory
1100010 2024-10-12T11:28:18 Z asli_bg Mecho (IOI09_mecho) C++11
13 / 100
1000 ms 19024 KB
#pragma GCC optimize("O3,unroll-loops")

#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define inset tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

//#define int long long

#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define FOR(i,a) for(int i=0;i<(a);i++)
#define FORE(i,a,b) for(int i=(a);i<(b);i++)

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vii;

#define cont(x) for(auto el:x) {cout<<el<<' ';} cout<<endl;
//#define endl '\n'
#define contp(x) for(auto el:x) {cout<<el.fi<<'-'<<el.se<<' ';} cout<<endl;
#define pb push_back

#define sp <<' '<<

#define DEBUG(x) {cout<<(#x) sp x<<endl;}

const int MAXN=805;
const int INF=1e9;

int n,s;
vector<string> grid;
set<pii> ari;
int mark[MAXN][MAXN];

set<pii> hive;

pii bas,son;

int yon1[4]={1,-1,0,0};
int yon2[4]={0,0,-1,1};
//sag, sol, asagi, yukari

bool isvalid(int x,int y,bool f){
    if(x>=n or y>=n or x<0 or y<0) return false;
    if(f){
        if(grid[x][y]!='G') return false;
        if(hive.count({x,y})) return false;
    }
    else{
        if(grid[x][y]!='G' and grid[x][y]!='D') return false;
    }
    return true;
}

bool check(int deg){
    //düz shortest path bfs
    map<pii,bool> vis;
    queue<pair<pii,int>> q;
    q.push({bas,0});
    vis[bas]=true;

    //cout<<"DEEEEEG" sp deg<<endl;

    while(!q.empty()){
        auto el=q.front();
        q.pop();

        int adim=el.se;
        int x=el.fi.fi;
        int y=el.fi.se;
        //cout<<"control" sp adim sp x sp y<<endl;

        FOR(i,4){
            int yenix=x+yon1[i];
            int yeniy=y+yon2[i];

            if(!isvalid(yenix,yeniy,false)) continue;
            if(vis[{yenix,yeniy}]) continue;
            
            int sure=adim/s;
            //DEBUG(sure);
            //DEBUG(yenix);
            //DEBUG(yeniy);
            if(mark[yenix][yeniy]<deg+sure) continue;
            if((adim+1)%s==0){
                if(mark[yenix][yeniy]==deg+sure) continue;   
            }

            q.push({{yenix,yeniy},adim+1});
            vis[{yenix,yeniy}]=true;
        }
    }

    return vis[son];
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>s;
    grid.resize(n);
    FOR(i,n){
        cin>>grid[i];
    }

    FOR(i,n){
        FOR(j,n){
            if(grid[i][j]=='H'){
                hive.insert({i,j});
                mark[i][j]=0;
            }
            if(grid[i][j]=='M') {
                bas={i,j};
                mark[i][j]=INF;
            }
            if(grid[i][j]=='D'){
                son={i,j};
                mark[i][j]=INF;
            }
        }
    }

    FOR(i,n){ //x kez ilerle
        set<pii> tut;

        for(auto el:hive){
            FOR(i,4){
                int yenix=el.fi+yon1[i];
                int yeniy=el.se+yon2[i];
                if(isvalid(yenix,yeniy,true)){
                    tut.insert({yenix,yeniy});
                }
            }
        }

        for(auto el:tut){
            mark[el.fi][el.se]=i+1;
            hive.insert(el);
        }
    }

    /*FOR(i,n){
        FOR(j,n) cout<<mark[i][j]<<' ';
        cout<<endl;
    }
    cout<<endl;*/


    int l=0;
    int r=n;
    while(l+1<r){
        int mid=(l+r)/2;
        if(check(mid)) l=mid;
        else r=mid;
    }

    cout<<l-1<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Correct 0 ms 348 KB Output is correct
7 Execution timed out 1101 ms 17168 KB Time limit exceeded
8 Correct 1 ms 348 KB Output is 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 Incorrect 2 ms 2652 KB Output isn't correct
13 Incorrect 15 ms 604 KB Output isn't correct
14 Correct 33 ms 2652 KB Output is correct
15 Incorrect 1 ms 348 KB Output isn't correct
16 Incorrect 0 ms 348 KB Output isn't correct
17 Incorrect 0 ms 348 KB Output isn't correct
18 Incorrect 1 ms 348 KB Output isn't correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Incorrect 0 ms 348 KB Output isn't correct
21 Incorrect 0 ms 348 KB Output isn't correct
22 Incorrect 0 ms 348 KB Output isn't correct
23 Incorrect 1 ms 348 KB Output isn't correct
24 Incorrect 0 ms 348 KB Output isn't correct
25 Incorrect 0 ms 2396 KB Output isn't correct
26 Incorrect 1 ms 2396 KB Output isn't correct
27 Incorrect 0 ms 2396 KB Output isn't correct
28 Incorrect 1 ms 2396 KB Output isn't correct
29 Incorrect 0 ms 2396 KB Output isn't correct
30 Incorrect 1 ms 2396 KB Output isn't correct
31 Incorrect 1 ms 2396 KB Output isn't correct
32 Incorrect 1 ms 2396 KB Output isn't correct
33 Incorrect 3 ms 2568 KB Output isn't correct
34 Incorrect 9 ms 2652 KB Output isn't correct
35 Execution timed out 1100 ms 5576 KB Time limit exceeded
36 Incorrect 4 ms 2652 KB Output isn't correct
37 Incorrect 12 ms 2652 KB Output isn't correct
38 Execution timed out 1100 ms 5828 KB Time limit exceeded
39 Incorrect 6 ms 2648 KB Output isn't correct
40 Incorrect 17 ms 2652 KB Output isn't correct
41 Execution timed out 1076 ms 5968 KB Time limit exceeded
42 Incorrect 8 ms 2652 KB Output isn't correct
43 Incorrect 21 ms 2836 KB Output isn't correct
44 Execution timed out 1057 ms 6164 KB Time limit exceeded
45 Incorrect 9 ms 2648 KB Output isn't correct
46 Incorrect 26 ms 2904 KB Output isn't correct
47 Execution timed out 1074 ms 6180 KB Time limit exceeded
48 Incorrect 12 ms 2908 KB Output isn't correct
49 Incorrect 32 ms 2968 KB Output isn't correct
50 Execution timed out 1068 ms 6436 KB Time limit exceeded
51 Incorrect 14 ms 2908 KB Output isn't correct
52 Incorrect 37 ms 2908 KB Output isn't correct
53 Execution timed out 1057 ms 6480 KB Time limit exceeded
54 Incorrect 17 ms 2904 KB Output isn't correct
55 Incorrect 44 ms 2904 KB Output isn't correct
56 Execution timed out 1077 ms 6440 KB Time limit exceeded
57 Incorrect 21 ms 1112 KB Output isn't correct
58 Incorrect 51 ms 1112 KB Output isn't correct
59 Execution timed out 1047 ms 6584 KB Time limit exceeded
60 Incorrect 25 ms 1112 KB Output isn't correct
61 Incorrect 59 ms 1116 KB Output isn't correct
62 Execution timed out 1071 ms 7024 KB Time limit exceeded
63 Execution timed out 1037 ms 5200 KB Time limit exceeded
64 Execution timed out 1010 ms 4476 KB Time limit exceeded
65 Execution timed out 1032 ms 4432 KB Time limit exceeded
66 Execution timed out 1060 ms 5204 KB Time limit exceeded
67 Execution timed out 1070 ms 4948 KB Time limit exceeded
68 Execution timed out 1050 ms 12884 KB Time limit exceeded
69 Execution timed out 1057 ms 13020 KB Time limit exceeded
70 Execution timed out 1020 ms 12844 KB Time limit exceeded
71 Execution timed out 1061 ms 12904 KB Time limit exceeded
72 Execution timed out 1030 ms 12744 KB Time limit exceeded
73 Execution timed out 1102 ms 18808 KB Time limit exceeded
74 Execution timed out 1042 ms 18768 KB Time limit exceeded
75 Execution timed out 1027 ms 18768 KB Time limit exceeded
76 Execution timed out 1049 ms 18768 KB Time limit exceeded
77 Execution timed out 1031 ms 19024 KB Time limit exceeded
78 Execution timed out 1064 ms 18516 KB Time limit exceeded
79 Execution timed out 1060 ms 18560 KB Time limit exceeded
80 Execution timed out 1026 ms 18512 KB Time limit exceeded
81 Execution timed out 1060 ms 18448 KB Time limit exceeded
82 Execution timed out 1040 ms 18668 KB Time limit exceeded
83 Execution timed out 1077 ms 18524 KB Time limit exceeded
84 Execution timed out 1055 ms 18476 KB Time limit exceeded
85 Execution timed out 1035 ms 18512 KB Time limit exceeded
86 Execution timed out 1032 ms 18512 KB Time limit exceeded
87 Execution timed out 1073 ms 18524 KB Time limit exceeded
88 Execution timed out 1042 ms 18256 KB Time limit exceeded
89 Execution timed out 1049 ms 17944 KB Time limit exceeded
90 Execution timed out 1065 ms 17884 KB Time limit exceeded
91 Execution timed out 1049 ms 17696 KB Time limit exceeded
92 Execution timed out 1038 ms 17696 KB Time limit exceeded