# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
885978 |
2023-12-11T09:19:34 Z |
JakobZorz |
Mecho (IOI09_mecho) |
C++17 |
|
1000 ms |
3320 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=-1,r=4e5;
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 |
4 ms |
504 KB |
Output is correct |
2 |
Correct |
3 ms |
600 KB |
Output is correct |
3 |
Correct |
3 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
452 KB |
Output is correct |
5 |
Correct |
3 ms |
348 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
974 ms |
2272 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
3 ms |
348 KB |
Output is correct |
10 |
Correct |
3 ms |
344 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
5 ms |
348 KB |
Output is correct |
13 |
Correct |
6 ms |
348 KB |
Output is correct |
14 |
Correct |
8 ms |
484 KB |
Output is correct |
15 |
Correct |
3 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
348 KB |
Output is correct |
17 |
Correct |
4 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
348 KB |
Output is correct |
19 |
Correct |
4 ms |
348 KB |
Output is correct |
20 |
Correct |
5 ms |
348 KB |
Output is correct |
21 |
Correct |
4 ms |
348 KB |
Output is correct |
22 |
Correct |
5 ms |
460 KB |
Output is correct |
23 |
Correct |
5 ms |
348 KB |
Output is correct |
24 |
Correct |
5 ms |
348 KB |
Output is correct |
25 |
Correct |
6 ms |
464 KB |
Output is correct |
26 |
Correct |
6 ms |
344 KB |
Output is correct |
27 |
Correct |
6 ms |
344 KB |
Output is correct |
28 |
Correct |
7 ms |
348 KB |
Output is correct |
29 |
Correct |
7 ms |
348 KB |
Output is correct |
30 |
Correct |
7 ms |
348 KB |
Output is correct |
31 |
Correct |
8 ms |
348 KB |
Output is correct |
32 |
Correct |
8 ms |
348 KB |
Output is correct |
33 |
Correct |
105 ms |
604 KB |
Output is correct |
34 |
Correct |
107 ms |
604 KB |
Output is correct |
35 |
Correct |
153 ms |
784 KB |
Output is correct |
36 |
Correct |
135 ms |
792 KB |
Output is correct |
37 |
Correct |
143 ms |
792 KB |
Output is correct |
38 |
Correct |
205 ms |
852 KB |
Output is correct |
39 |
Correct |
174 ms |
860 KB |
Output is correct |
40 |
Correct |
173 ms |
880 KB |
Output is correct |
41 |
Correct |
256 ms |
856 KB |
Output is correct |
42 |
Correct |
207 ms |
860 KB |
Output is correct |
43 |
Correct |
209 ms |
984 KB |
Output is correct |
44 |
Correct |
315 ms |
1032 KB |
Output is correct |
45 |
Correct |
244 ms |
856 KB |
Output is correct |
46 |
Correct |
256 ms |
1084 KB |
Output is correct |
47 |
Correct |
389 ms |
1132 KB |
Output is correct |
48 |
Correct |
288 ms |
1220 KB |
Output is correct |
49 |
Correct |
304 ms |
1116 KB |
Output is correct |
50 |
Correct |
470 ms |
1312 KB |
Output is correct |
51 |
Correct |
371 ms |
1368 KB |
Output is correct |
52 |
Correct |
383 ms |
1340 KB |
Output is correct |
53 |
Correct |
555 ms |
1400 KB |
Output is correct |
54 |
Correct |
395 ms |
1372 KB |
Output is correct |
55 |
Correct |
397 ms |
1480 KB |
Output is correct |
56 |
Correct |
620 ms |
1552 KB |
Output is correct |
57 |
Correct |
479 ms |
1656 KB |
Output is correct |
58 |
Correct |
480 ms |
1624 KB |
Output is correct |
59 |
Correct |
715 ms |
1680 KB |
Output is correct |
60 |
Correct |
508 ms |
1876 KB |
Output is correct |
61 |
Correct |
541 ms |
1872 KB |
Output is correct |
62 |
Correct |
836 ms |
2112 KB |
Output is correct |
63 |
Correct |
829 ms |
1628 KB |
Output is correct |
64 |
Correct |
793 ms |
1824 KB |
Output is correct |
65 |
Correct |
796 ms |
1624 KB |
Output is correct |
66 |
Correct |
749 ms |
1816 KB |
Output is correct |
67 |
Correct |
830 ms |
1804 KB |
Output is correct |
68 |
Correct |
724 ms |
2132 KB |
Output is correct |
69 |
Correct |
629 ms |
1924 KB |
Output is correct |
70 |
Correct |
704 ms |
1920 KB |
Output is correct |
71 |
Correct |
704 ms |
1920 KB |
Output is correct |
72 |
Correct |
666 ms |
2132 KB |
Output is correct |
73 |
Correct |
883 ms |
3200 KB |
Output is correct |
74 |
Correct |
941 ms |
3080 KB |
Output is correct |
75 |
Correct |
893 ms |
3304 KB |
Output is correct |
76 |
Correct |
883 ms |
3072 KB |
Output is correct |
77 |
Correct |
925 ms |
3320 KB |
Output is correct |
78 |
Correct |
932 ms |
2640 KB |
Output is correct |
79 |
Correct |
843 ms |
2640 KB |
Output is correct |
80 |
Correct |
860 ms |
2896 KB |
Output is correct |
81 |
Correct |
875 ms |
2644 KB |
Output is correct |
82 |
Correct |
916 ms |
2864 KB |
Output is correct |
83 |
Execution timed out |
1059 ms |
2736 KB |
Time limit exceeded |
84 |
Correct |
912 ms |
2504 KB |
Output is correct |
85 |
Correct |
912 ms |
2504 KB |
Output is correct |
86 |
Correct |
929 ms |
2512 KB |
Output is correct |
87 |
Correct |
910 ms |
2508 KB |
Output is correct |
88 |
Execution timed out |
1004 ms |
2552 KB |
Time limit exceeded |
89 |
Correct |
944 ms |
2528 KB |
Output is correct |
90 |
Correct |
948 ms |
2532 KB |
Output is correct |
91 |
Correct |
925 ms |
2528 KB |
Output is correct |
92 |
Correct |
941 ms |
2528 KB |
Output is correct |