# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
484547 |
2021-11-04T11:44:33 Z |
Sho10 |
Mecho (IOI09_mecho) |
C++17 |
|
266 ms |
14464 KB |
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define aint(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 998244353
#define PI 3.14159265359
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,s,sx,sy,dbees[805][805],d[805][805],viz[505][505],fx,fy;
pair<ll,ll>direction[5];
char a[805][805];
vector<pair<ll,ll>>hive;
ll check(ll x,ll y){
if(x>=1&&y>=1&&x<=n&&y<=n){
return 1;
}else return 0;
}
ll verif(ll time){
for(ll i=1;i<=n;i++)
for(ll j=1;j<=n;j++)
{
d[i][j]=LINF;
viz[i][j]=0;
}
queue<pair<ll,ll>>q;
d[sx][sy]=0;
viz[sx][sy]=1;
q.push(mp(sx,sy));
if(dbees[sx][sy]<=time){
q.pop();
}
while(!q.empty()){
ll x,y;
x=q.front().f;
y=q.front().s;
//cout<<x<<' '<<y<<endl;
q.pop();
for(ll i=0;i<4;i++)
{
ll xx,yy;
xx=x+direction[i].f;
yy=y+direction[i].s;
if(a[xx][yy]=='T'||a[xx][yy]=='H'){
continue;
}
if(check(xx,yy)==0){
continue;
}
if(viz[xx][yy]==1){
continue;
}
if((d[x][y]+1)/s>=dbees[xx][yy]-time){
continue;
}
viz[xx][yy]=1;
d[xx][yy]=d[x][y]+1;
q.push(mp(xx,yy));
}
}
ll ans=0;
for(ll i=0;i<4;i++)
{
ll x=fx+direction[i].f,y=fy+direction[i].s;
if(check(x,y)==0){
continue;
}
if(viz[x][y]==0){
continue;
}
if((d[x][y]/s)<dbees[x][y]-time){
ans=1;
}
}
return ans;
}
int32_t main(){
//CODE_START;
direction[0]=mp(-1,0);
direction[1]=mp(1,0);
direction[2]=mp(0,-1);
direction[3]=mp(0,1);
cin>>n>>s;
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=n;j++)
{
cin>>a[i][j];
if(a[i][j]=='M'){
sx=i;
sy=j;
}else if(a[i][j]=='H'){
hive.pb(mp(i,j));
}else if(a[i][j]=='D'){
fx=i;
fy=j;
}
}
}
for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=n;j++)
{
dbees[i][j]=LINF;
}
}
queue<pair<ll,ll>>q;
for(auto it : hive){
q.push(it);
dbees[it.f][it.s]=0;
}
while(!q.empty()){
ll x,y;
x=q.front().f;
y=q.front().s;
q.pop();
for(ll i=0;i<4;i++)
{
ll xx,yy;
xx=x+direction[i].f;
yy=y+direction[i].s;
if(a[xx][yy]=='T'||a[xx][yy]=='D'||a[xx][yy]=='H'){
continue;
}
if(check(xx,yy)&&viz[xx][yy]==0){
viz[xx][yy]=1;
q.push(mp(xx,yy));
dbees[xx][yy]=dbees[x][y]+1;
}
}
}
ll l=0,r=n*n;
//cout<<"DA"<<endl;
while(l<=r){
ll mid=(l+r)/2;
// cout<<mid<<endl;
if(verif(mid)){
l=mid+1;
}else {
r=mid-1;
}
}
cout<<l-1<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Incorrect |
116 ms |
13808 KB |
Output isn't correct |
8 |
Correct |
1 ms |
460 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
940 KB |
Output is correct |
14 |
Correct |
1 ms |
1100 KB |
Output is correct |
15 |
Correct |
0 ms |
588 KB |
Output is correct |
16 |
Correct |
1 ms |
588 KB |
Output is correct |
17 |
Correct |
1 ms |
588 KB |
Output is correct |
18 |
Correct |
1 ms |
588 KB |
Output is correct |
19 |
Correct |
1 ms |
716 KB |
Output is correct |
20 |
Correct |
1 ms |
716 KB |
Output is correct |
21 |
Correct |
1 ms |
844 KB |
Output is correct |
22 |
Correct |
1 ms |
844 KB |
Output is correct |
23 |
Correct |
1 ms |
972 KB |
Output is correct |
24 |
Correct |
1 ms |
972 KB |
Output is correct |
25 |
Correct |
1 ms |
1100 KB |
Output is correct |
26 |
Correct |
1 ms |
1100 KB |
Output is correct |
27 |
Correct |
1 ms |
1100 KB |
Output is correct |
28 |
Correct |
1 ms |
1100 KB |
Output is correct |
29 |
Correct |
1 ms |
1228 KB |
Output is correct |
30 |
Correct |
1 ms |
1228 KB |
Output is correct |
31 |
Correct |
1 ms |
1356 KB |
Output is correct |
32 |
Correct |
1 ms |
1356 KB |
Output is correct |
33 |
Correct |
13 ms |
6476 KB |
Output is correct |
34 |
Correct |
13 ms |
6424 KB |
Output is correct |
35 |
Correct |
34 ms |
6508 KB |
Output is correct |
36 |
Correct |
15 ms |
7356 KB |
Output is correct |
37 |
Correct |
20 ms |
7296 KB |
Output is correct |
38 |
Correct |
34 ms |
7372 KB |
Output is correct |
39 |
Correct |
18 ms |
8232 KB |
Output is correct |
40 |
Correct |
20 ms |
8208 KB |
Output is correct |
41 |
Correct |
43 ms |
8256 KB |
Output is correct |
42 |
Correct |
24 ms |
9164 KB |
Output is correct |
43 |
Correct |
23 ms |
9220 KB |
Output is correct |
44 |
Correct |
53 ms |
9220 KB |
Output is correct |
45 |
Incorrect |
31 ms |
10020 KB |
Output isn't correct |
46 |
Incorrect |
55 ms |
9924 KB |
Output isn't correct |
47 |
Incorrect |
38 ms |
9908 KB |
Output isn't correct |
48 |
Incorrect |
27 ms |
10608 KB |
Output isn't correct |
49 |
Incorrect |
56 ms |
10576 KB |
Output isn't correct |
50 |
Incorrect |
45 ms |
10596 KB |
Output isn't correct |
51 |
Incorrect |
33 ms |
11340 KB |
Output isn't correct |
52 |
Incorrect |
68 ms |
11332 KB |
Output isn't correct |
53 |
Incorrect |
59 ms |
11332 KB |
Output isn't correct |
54 |
Incorrect |
37 ms |
12076 KB |
Output isn't correct |
55 |
Incorrect |
75 ms |
12096 KB |
Output isn't correct |
56 |
Incorrect |
63 ms |
12060 KB |
Output isn't correct |
57 |
Incorrect |
42 ms |
12828 KB |
Output isn't correct |
58 |
Incorrect |
94 ms |
12880 KB |
Output isn't correct |
59 |
Incorrect |
74 ms |
12900 KB |
Output isn't correct |
60 |
Incorrect |
49 ms |
13616 KB |
Output isn't correct |
61 |
Incorrect |
102 ms |
13600 KB |
Output isn't correct |
62 |
Incorrect |
73 ms |
13556 KB |
Output isn't correct |
63 |
Incorrect |
115 ms |
13636 KB |
Output isn't correct |
64 |
Incorrect |
248 ms |
13752 KB |
Output isn't correct |
65 |
Incorrect |
237 ms |
13640 KB |
Output isn't correct |
66 |
Incorrect |
142 ms |
13648 KB |
Output isn't correct |
67 |
Incorrect |
266 ms |
13588 KB |
Output isn't correct |
68 |
Incorrect |
64 ms |
13688 KB |
Output isn't correct |
69 |
Correct |
78 ms |
13636 KB |
Output is correct |
70 |
Correct |
85 ms |
13612 KB |
Output is correct |
71 |
Correct |
73 ms |
13676 KB |
Output is correct |
72 |
Incorrect |
72 ms |
13636 KB |
Output isn't correct |
73 |
Correct |
64 ms |
14256 KB |
Output is correct |
74 |
Incorrect |
157 ms |
14224 KB |
Output isn't correct |
75 |
Incorrect |
186 ms |
14172 KB |
Output isn't correct |
76 |
Incorrect |
150 ms |
14148 KB |
Output isn't correct |
77 |
Incorrect |
177 ms |
14464 KB |
Output isn't correct |
78 |
Incorrect |
93 ms |
14020 KB |
Output isn't correct |
79 |
Incorrect |
99 ms |
14004 KB |
Output isn't correct |
80 |
Incorrect |
71 ms |
14020 KB |
Output isn't correct |
81 |
Incorrect |
89 ms |
14048 KB |
Output isn't correct |
82 |
Incorrect |
126 ms |
14156 KB |
Output isn't correct |
83 |
Incorrect |
119 ms |
13984 KB |
Output isn't correct |
84 |
Incorrect |
155 ms |
13892 KB |
Output isn't correct |
85 |
Incorrect |
92 ms |
13856 KB |
Output isn't correct |
86 |
Incorrect |
119 ms |
13964 KB |
Output isn't correct |
87 |
Incorrect |
139 ms |
14008 KB |
Output isn't correct |
88 |
Incorrect |
146 ms |
13892 KB |
Output isn't correct |
89 |
Incorrect |
109 ms |
13808 KB |
Output isn't correct |
90 |
Incorrect |
108 ms |
13856 KB |
Output isn't correct |
91 |
Incorrect |
115 ms |
13900 KB |
Output isn't correct |
92 |
Incorrect |
147 ms |
13904 KB |
Output isn't correct |