Submission #484549

# Submission time Handle Problem Language Result Execution time Memory
484549 2021-11-04T11:46:57 Z Sho10 Mecho (IOI09_mecho) C++17
54 / 100
242 ms 13564 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,ans=-1;
//cout<<"DA"<<endl;
while(l<=r){
    ll mid=(l+r)/2;
  //  cout<<mid<<endl;
    if(verif(mid)){
        l=mid+1;
        ans=mid;
    }else {
    r=mid-1;
}
}
cout<<ans<<endl;
}


# Verdict Execution time Memory Grader output
1 Correct 0 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 0 ms 332 KB Output is correct
7 Incorrect 121 ms 13252 KB Output isn't correct
8 Correct 0 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 0 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 972 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 0 ms 460 KB Output is correct
17 Correct 0 ms 588 KB Output is correct
18 Correct 0 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 1192 KB Output is correct
28 Correct 1 ms 1100 KB Output is correct
29 Correct 1 ms 1228 KB Output is correct
30 Correct 2 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 12 ms 6348 KB Output is correct
34 Correct 12 ms 6280 KB Output is correct
35 Correct 25 ms 6348 KB Output is correct
36 Correct 15 ms 7216 KB Output is correct
37 Correct 17 ms 7136 KB Output is correct
38 Correct 33 ms 7236 KB Output is correct
39 Correct 19 ms 8128 KB Output is correct
40 Correct 19 ms 8120 KB Output is correct
41 Correct 43 ms 8012 KB Output is correct
42 Correct 22 ms 8908 KB Output is correct
43 Correct 23 ms 8932 KB Output is correct
44 Correct 54 ms 8908 KB Output is correct
45 Incorrect 23 ms 9540 KB Output isn't correct
46 Incorrect 48 ms 9660 KB Output isn't correct
47 Incorrect 39 ms 9672 KB Output isn't correct
48 Incorrect 27 ms 10292 KB Output isn't correct
49 Incorrect 56 ms 10324 KB Output isn't correct
50 Incorrect 44 ms 10240 KB Output isn't correct
51 Incorrect 36 ms 10956 KB Output isn't correct
52 Incorrect 69 ms 10904 KB Output isn't correct
53 Incorrect 47 ms 10920 KB Output isn't correct
54 Incorrect 42 ms 11588 KB Output isn't correct
55 Incorrect 78 ms 11816 KB Output isn't correct
56 Incorrect 59 ms 11624 KB Output isn't correct
57 Incorrect 41 ms 12236 KB Output isn't correct
58 Incorrect 90 ms 12248 KB Output isn't correct
59 Incorrect 69 ms 12300 KB Output isn't correct
60 Incorrect 48 ms 12940 KB Output isn't correct
61 Incorrect 110 ms 13020 KB Output isn't correct
62 Incorrect 76 ms 12992 KB Output isn't correct
63 Incorrect 100 ms 12912 KB Output isn't correct
64 Incorrect 236 ms 13020 KB Output isn't correct
65 Incorrect 242 ms 12996 KB Output isn't correct
66 Incorrect 120 ms 12992 KB Output isn't correct
67 Incorrect 230 ms 12996 KB Output isn't correct
68 Incorrect 64 ms 13012 KB Output isn't correct
69 Correct 72 ms 13060 KB Output is correct
70 Correct 66 ms 12948 KB Output is correct
71 Correct 72 ms 13032 KB Output is correct
72 Incorrect 72 ms 12992 KB Output isn't correct
73 Correct 62 ms 13528 KB Output is correct
74 Incorrect 150 ms 13512 KB Output isn't correct
75 Incorrect 156 ms 13564 KB Output isn't correct
76 Incorrect 152 ms 13508 KB Output isn't correct
77 Incorrect 150 ms 13508 KB Output isn't correct
78 Incorrect 92 ms 13420 KB Output isn't correct
79 Incorrect 96 ms 13484 KB Output isn't correct
80 Incorrect 85 ms 13508 KB Output isn't correct
81 Incorrect 86 ms 13316 KB Output isn't correct
82 Incorrect 120 ms 13420 KB Output isn't correct
83 Incorrect 101 ms 13252 KB Output isn't correct
84 Incorrect 123 ms 13344 KB Output isn't correct
85 Incorrect 102 ms 13272 KB Output isn't correct
86 Incorrect 113 ms 13344 KB Output isn't correct
87 Incorrect 134 ms 13252 KB Output isn't correct
88 Incorrect 137 ms 13252 KB Output isn't correct
89 Incorrect 107 ms 13380 KB Output isn't correct
90 Incorrect 106 ms 13168 KB Output isn't correct
91 Incorrect 108 ms 13276 KB Output isn't correct
92 Incorrect 132 ms 13156 KB Output isn't correct