Submission #885966

# Submission time Handle Problem Language Result Execution time Memory
885966 2023-12-11T08:57:08 Z JakobZorz Mecho (IOI09_mecho) C++17
72 / 100
1000 ms 3420 KB
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<math.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<iomanip>
#include<cstring>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
//const int MOD=1e9+7;
//typedef pair<ll,ll>Point;
//typedef pair<ll,ll>Line;
//#define x first
//#define y second

int n,s;
vector<string>m;
vector<string>cm;
queue<pair<int,int>>q1,q2;

vector<pair<int,int>>get_nbs(pair<int,int>pos){
    vector<pair<int,int>>res;
    if(pos.first!=0)
        res.emplace_back(pos.first-1,pos.second);
    if(pos.second!=0)
        res.emplace_back(pos.first,pos.second-1);
    if(pos.first!=n-1)
        res.emplace_back(pos.first+1,pos.second);
    if(pos.second!=n-1)
        res.emplace_back(pos.first,pos.second+1);
    return res;
}

void spread_bees(){
    queue<pair<int,int>>q;
    while(q2.size()){
        pair<int,int>curr=q2.front();
        q2.pop();
        vector<pair<int,int>>nbs=get_nbs(curr);
        for(pair<int,int>i:nbs){
            if(cm[i.first][i.second]=='H')
                continue;
            if(cm[i.first][i.second]=='T')
                continue;
            if(cm[i.first][i.second]=='D')
                continue;
            cm[i.first][i.second]='H';
            q.push(i);
        }
    }
    q2=q;
}

bool check(int waits){
    cm=m;
    q1=queue<pair<int,int>>();
    q2=queue<pair<int,int>>();
    
    for(int x=0;x<n;x++)
        for(int y=0;y<n;y++){
            if(cm[x][y]=='H')
                q2.push({x,y});
            
            if(cm[x][y]=='M')
                q1.push({x,y});
        }
    
    while(waits--){
        spread_bees();
    }
    
    while(q1.size()||q2.size()){
        for(int i=0;i<s;i++){
            queue<pair<int,int>>q;
            while(q1.size()){
                pair<int,int>curr=q1.front();
                q1.pop();
                if(cm[curr.first][curr.second]!='M')
                    continue;
                vector<pair<int,int>>nbs=get_nbs(curr);
                for(pair<int,int>i:nbs){
                    if(cm[i.first][i.second]=='H')
                        continue;
                    if(cm[i.first][i.second]=='T')
                        continue;
                    if(cm[i.first][i.second]=='D')
                        return true;
                    if(cm[i.first][i.second]=='M')
                        continue;
                    cm[i.first][i.second]='M';
                    q.push(i);
                }
            }
            q1=q;
        }
        
        spread_bees();
    }
    
    return false;
}

void solve(){
    cin>>n>>s;
    m.resize(n);
    for(string&i:m)
        cin>>i;
    
    int l=0,r=2e5;
    while(l<r-1){
        int m=(l+r)/2;
        if(check(m))
            l=m;
        else
            r=m;
    }
    cout<<l<<"\n";
}

int main(){
    ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
    //freopen("bank.in","r",stdin);freopen("bank.out","w",stdout);
    int t=1;//cin>>t;
    while(t--)solve();
    return 0;
}

/*
 
7 3
TTTTTTT
TGGGGGT
TGGGGGT
MGGGGGD
TGGGGGT
TGGGGGT
THHHHHT
 
 
7 3
TTTTTTT
TGGGGGT
TGGGGGT
MGGGGGD
TGGGGGT
TGGGGGT
TGHHGGT
 
 */
# Verdict Execution time Memory Grader output
1 Correct 9 ms 348 KB Output is correct
2 Correct 9 ms 348 KB Output is correct
3 Correct 9 ms 348 KB Output is correct
4 Correct 9 ms 348 KB Output is correct
5 Correct 9 ms 348 KB Output is correct
6 Correct 9 ms 348 KB Output is correct
7 Correct 926 ms 2648 KB Output is correct
8 Incorrect 9 ms 348 KB Output isn't correct
9 Correct 9 ms 344 KB Output is correct
10 Correct 9 ms 344 KB Output is correct
11 Correct 9 ms 460 KB Output is correct
12 Correct 11 ms 348 KB Output is correct
13 Correct 12 ms 456 KB Output is correct
14 Incorrect 15 ms 348 KB Output isn't correct
15 Correct 9 ms 344 KB Output is correct
16 Correct 9 ms 348 KB Output is correct
17 Correct 10 ms 348 KB Output is correct
18 Correct 10 ms 348 KB Output is correct
19 Correct 10 ms 348 KB Output is correct
20 Correct 10 ms 348 KB Output is correct
21 Correct 10 ms 344 KB Output is correct
22 Correct 14 ms 860 KB Output is correct
23 Correct 11 ms 348 KB Output is correct
24 Correct 18 ms 348 KB Output is correct
25 Correct 12 ms 348 KB Output is correct
26 Correct 13 ms 348 KB Output is correct
27 Correct 13 ms 348 KB Output is correct
28 Correct 12 ms 344 KB Output is correct
29 Correct 13 ms 480 KB Output is correct
30 Correct 13 ms 484 KB Output is correct
31 Correct 14 ms 348 KB Output is correct
32 Correct 14 ms 488 KB Output is correct
33 Correct 115 ms 604 KB Output is correct
34 Correct 102 ms 604 KB Output is correct
35 Correct 195 ms 604 KB Output is correct
36 Correct 154 ms 956 KB Output is correct
37 Correct 135 ms 952 KB Output is correct
38 Correct 260 ms 856 KB Output is correct
39 Correct 191 ms 856 KB Output is correct
40 Correct 169 ms 1088 KB Output is correct
41 Correct 328 ms 1092 KB Output is correct
42 Correct 246 ms 1232 KB Output is correct
43 Correct 205 ms 1368 KB Output is correct
44 Correct 407 ms 1240 KB Output is correct
45 Correct 297 ms 1616 KB Output is correct
46 Correct 260 ms 1372 KB Output is correct
47 Correct 496 ms 1400 KB Output is correct
48 Correct 339 ms 1368 KB Output is correct
49 Correct 301 ms 1584 KB Output is correct
50 Correct 587 ms 1368 KB Output is correct
51 Incorrect 372 ms 1876 KB Output isn't correct
52 Correct 360 ms 1772 KB Output is correct
53 Correct 698 ms 1784 KB Output is correct
54 Incorrect 380 ms 2132 KB Output isn't correct
55 Correct 412 ms 1968 KB Output is correct
56 Correct 814 ms 2132 KB Output is correct
57 Incorrect 388 ms 2196 KB Output isn't correct
58 Correct 475 ms 2192 KB Output is correct
59 Correct 948 ms 2212 KB Output is correct
60 Incorrect 383 ms 2644 KB Output isn't correct
61 Correct 517 ms 2432 KB Output is correct
62 Execution timed out 1076 ms 2452 KB Time limit exceeded
63 Correct 704 ms 2396 KB Output is correct
64 Execution timed out 1084 ms 2392 KB Time limit exceeded
65 Correct 688 ms 2428 KB Output is correct
66 Correct 719 ms 2396 KB Output is correct
67 Incorrect 746 ms 2392 KB Output isn't correct
68 Correct 629 ms 2504 KB Output is correct
69 Correct 632 ms 2644 KB Output is correct
70 Correct 627 ms 2484 KB Output is correct
71 Correct 627 ms 2488 KB Output is correct
72 Correct 647 ms 2396 KB Output is correct
73 Correct 825 ms 3176 KB Output is correct
74 Correct 824 ms 2976 KB Output is correct
75 Correct 877 ms 3168 KB Output is correct
76 Correct 866 ms 3172 KB Output is correct
77 Correct 814 ms 3060 KB Output is correct
78 Incorrect 879 ms 3000 KB Output isn't correct
79 Correct 846 ms 2924 KB Output is correct
80 Correct 844 ms 3420 KB Output is correct
81 Correct 861 ms 3008 KB Output is correct
82 Correct 814 ms 3136 KB Output is correct
83 Correct 907 ms 2836 KB Output is correct
84 Correct 886 ms 3024 KB Output is correct
85 Correct 863 ms 2848 KB Output is correct
86 Correct 886 ms 3076 KB Output is correct
87 Correct 886 ms 2848 KB Output is correct
88 Correct 897 ms 2972 KB Output is correct
89 Correct 859 ms 2908 KB Output is correct
90 Correct 870 ms 2812 KB Output is correct
91 Correct 864 ms 2816 KB Output is correct
92 Correct 882 ms 2928 KB Output is correct