Submission #484555

# Submission time Handle Problem Language Result Execution time Memory
484555 2021-11-04T11:55:04 Z Sho10 Mecho (IOI09_mecho) C++17
4 / 100
1 ms 300 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[805][805],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;
ifstream cin("input.in");
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 Incorrect 0 ms 204 KB Output isn't correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Incorrect 0 ms 204 KB Output isn't correct
6 Incorrect 0 ms 204 KB Output isn't correct
7 Incorrect 0 ms 204 KB Output isn't correct
8 Correct 0 ms 204 KB Output is correct
9 Incorrect 0 ms 204 KB Output isn't correct
10 Incorrect 0 ms 204 KB Output isn't correct
11 Incorrect 1 ms 204 KB Output isn't correct
12 Incorrect 1 ms 204 KB Output isn't correct
13 Incorrect 0 ms 204 KB Output isn't correct
14 Correct 1 ms 204 KB Output is correct
15 Incorrect 0 ms 204 KB Output isn't correct
16 Incorrect 1 ms 204 KB Output isn't correct
17 Incorrect 0 ms 204 KB Output isn't correct
18 Incorrect 0 ms 204 KB Output isn't correct
19 Incorrect 0 ms 204 KB Output isn't correct
20 Incorrect 0 ms 204 KB Output isn't correct
21 Incorrect 0 ms 204 KB Output isn't correct
22 Incorrect 0 ms 204 KB Output isn't correct
23 Incorrect 0 ms 204 KB Output isn't correct
24 Incorrect 0 ms 204 KB Output isn't correct
25 Incorrect 1 ms 204 KB Output isn't correct
26 Incorrect 0 ms 204 KB Output isn't correct
27 Incorrect 0 ms 204 KB Output isn't correct
28 Incorrect 1 ms 204 KB Output isn't correct
29 Incorrect 0 ms 204 KB Output isn't correct
30 Incorrect 0 ms 204 KB Output isn't correct
31 Incorrect 0 ms 204 KB Output isn't correct
32 Incorrect 0 ms 204 KB Output isn't correct
33 Incorrect 0 ms 204 KB Output isn't correct
34 Incorrect 0 ms 204 KB Output isn't correct
35 Incorrect 0 ms 204 KB Output isn't correct
36 Incorrect 0 ms 204 KB Output isn't correct
37 Incorrect 0 ms 204 KB Output isn't correct
38 Incorrect 0 ms 204 KB Output isn't correct
39 Incorrect 0 ms 204 KB Output isn't correct
40 Incorrect 0 ms 204 KB Output isn't correct
41 Incorrect 0 ms 204 KB Output isn't correct
42 Incorrect 0 ms 204 KB Output isn't correct
43 Incorrect 1 ms 204 KB Output isn't correct
44 Incorrect 0 ms 204 KB Output isn't correct
45 Incorrect 0 ms 204 KB Output isn't correct
46 Incorrect 0 ms 204 KB Output isn't correct
47 Incorrect 1 ms 204 KB Output isn't correct
48 Incorrect 0 ms 204 KB Output isn't correct
49 Incorrect 0 ms 204 KB Output isn't correct
50 Incorrect 0 ms 204 KB Output isn't correct
51 Incorrect 0 ms 204 KB Output isn't correct
52 Incorrect 0 ms 204 KB Output isn't correct
53 Incorrect 0 ms 204 KB Output isn't correct
54 Incorrect 0 ms 204 KB Output isn't correct
55 Incorrect 0 ms 204 KB Output isn't correct
56 Incorrect 0 ms 204 KB Output isn't correct
57 Incorrect 0 ms 204 KB Output isn't correct
58 Incorrect 0 ms 204 KB Output isn't correct
59 Incorrect 0 ms 300 KB Output isn't correct
60 Incorrect 0 ms 204 KB Output isn't correct
61 Incorrect 0 ms 204 KB Output isn't correct
62 Incorrect 0 ms 204 KB Output isn't correct
63 Incorrect 0 ms 204 KB Output isn't correct
64 Incorrect 0 ms 204 KB Output isn't correct
65 Incorrect 0 ms 204 KB Output isn't correct
66 Incorrect 0 ms 204 KB Output isn't correct
67 Correct 0 ms 204 KB Output is correct
68 Incorrect 0 ms 204 KB Output isn't correct
69 Incorrect 1 ms 204 KB Output isn't correct
70 Incorrect 1 ms 204 KB Output isn't correct
71 Incorrect 0 ms 204 KB Output isn't correct
72 Incorrect 0 ms 204 KB Output isn't correct
73 Incorrect 0 ms 204 KB Output isn't correct
74 Incorrect 0 ms 204 KB Output isn't correct
75 Incorrect 0 ms 204 KB Output isn't correct
76 Incorrect 0 ms 204 KB Output isn't correct
77 Incorrect 1 ms 204 KB Output isn't correct
78 Correct 0 ms 204 KB Output is correct
79 Incorrect 0 ms 204 KB Output isn't correct
80 Incorrect 0 ms 204 KB Output isn't correct
81 Incorrect 0 ms 204 KB Output isn't correct
82 Incorrect 0 ms 204 KB Output isn't correct
83 Incorrect 0 ms 204 KB Output isn't correct
84 Incorrect 1 ms 204 KB Output isn't correct
85 Incorrect 1 ms 204 KB Output isn't correct
86 Incorrect 0 ms 204 KB Output isn't correct
87 Incorrect 1 ms 204 KB Output isn't correct
88 Incorrect 0 ms 204 KB Output isn't correct
89 Incorrect 1 ms 204 KB Output isn't correct
90 Incorrect 0 ms 204 KB Output isn't correct
91 Incorrect 0 ms 204 KB Output isn't correct
92 Incorrect 0 ms 204 KB Output isn't correct