Submission #885973

# Submission time Handle Problem Language Result Execution time Memory
885973 2023-12-11T09:14:37 Z JakobZorz Mecho (IOI09_mecho) C++17
60 / 100
908 ms 3192 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,cm;
vector<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(){
    vector<pair<int,int>>q;
    for(pair<int,int>curr:q2){
        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_back(i);
        }
    }
    q2=q;
}

bool check(int waits){
    cm=m;
    q1.clear();
    q2.clear();
    
    for(int x=0;x<n;x++)
        for(int y=0;y<n;y++){
            if(cm[x][y]=='H')
                q2.emplace_back(x,y);
            
            if(cm[x][y]=='M')
                q1.emplace_back(x,y);
        }
    
    while(waits--){
        spread_bees();
    }
    
    while(q1.size()||q2.size()){
        for(int i=0;i<s;i++){
            vector<pair<int,int>>q;
            for(pair<int,int>curr:q1){
                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_back(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=5e4;
    while(l<r-1){
        int m=(l+r)/2;
        if(check(m))
            l=m;
        else
            r=m;
    }
    if(l==5e4-1)
        l=-1;
    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 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 372 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 908 ms 2276 KB Output is correct
8 Incorrect 1 ms 344 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 3 ms 348 KB Output is correct
13 Correct 3 ms 348 KB Output is correct
14 Incorrect 5 ms 348 KB Output isn't correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 3 ms 348 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
27 Correct 4 ms 348 KB Output is correct
28 Correct 4 ms 344 KB Output is correct
29 Correct 5 ms 344 KB Output is correct
30 Correct 4 ms 348 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 5 ms 348 KB Output is correct
33 Incorrect 70 ms 604 KB Output isn't correct
34 Correct 84 ms 604 KB Output is correct
35 Correct 146 ms 600 KB Output is correct
36 Incorrect 73 ms 600 KB Output isn't correct
37 Correct 115 ms 604 KB Output is correct
38 Correct 201 ms 852 KB Output is correct
39 Incorrect 73 ms 860 KB Output isn't correct
40 Correct 141 ms 1112 KB Output is correct
41 Correct 250 ms 860 KB Output is correct
42 Incorrect 77 ms 856 KB Output isn't correct
43 Incorrect 144 ms 972 KB Output isn't correct
44 Correct 308 ms 1104 KB Output is correct
45 Incorrect 78 ms 860 KB Output isn't correct
46 Incorrect 151 ms 1080 KB Output isn't correct
47 Correct 371 ms 1176 KB Output is correct
48 Incorrect 81 ms 1220 KB Output isn't correct
49 Incorrect 153 ms 1360 KB Output isn't correct
50 Correct 452 ms 1308 KB Output is correct
51 Incorrect 86 ms 1112 KB Output isn't correct
52 Incorrect 150 ms 1116 KB Output isn't correct
53 Correct 525 ms 1788 KB Output is correct
54 Incorrect 87 ms 1372 KB Output isn't correct
55 Incorrect 155 ms 1488 KB Output isn't correct
56 Correct 617 ms 1616 KB Output is correct
57 Incorrect 90 ms 1624 KB Output isn't correct
58 Incorrect 158 ms 1636 KB Output isn't correct
59 Correct 702 ms 1912 KB Output is correct
60 Incorrect 95 ms 1784 KB Output isn't correct
61 Incorrect 169 ms 1872 KB Output isn't correct
62 Correct 829 ms 2128 KB Output is correct
63 Correct 695 ms 1624 KB Output is correct
64 Correct 734 ms 1624 KB Output is correct
65 Correct 682 ms 1820 KB Output is correct
66 Correct 709 ms 1824 KB Output is correct
67 Incorrect 745 ms 1820 KB Output isn't correct
68 Correct 594 ms 1924 KB Output is correct
69 Correct 549 ms 1884 KB Output is correct
70 Correct 608 ms 2128 KB Output is correct
71 Correct 616 ms 1920 KB Output is correct
72 Correct 593 ms 1884 KB Output is correct
73 Correct 767 ms 3076 KB Output is correct
74 Correct 765 ms 3192 KB Output is correct
75 Correct 837 ms 3080 KB Output is correct
76 Correct 825 ms 3084 KB Output is correct
77 Correct 763 ms 3076 KB Output is correct
78 Incorrect 855 ms 2640 KB Output isn't correct
79 Correct 788 ms 2640 KB Output is correct
80 Correct 818 ms 2644 KB Output is correct
81 Correct 838 ms 2640 KB Output is correct
82 Correct 792 ms 2644 KB Output is correct
83 Correct 865 ms 2508 KB Output is correct
84 Correct 827 ms 2512 KB Output is correct
85 Correct 820 ms 2508 KB Output is correct
86 Correct 851 ms 2512 KB Output is correct
87 Correct 833 ms 2512 KB Output is correct
88 Correct 858 ms 2420 KB Output is correct
89 Correct 812 ms 2640 KB Output is correct
90 Correct 838 ms 2532 KB Output is correct
91 Correct 853 ms 2640 KB Output is correct
92 Correct 853 ms 2536 KB Output is correct