Submission #442172

# Submission time Handle Problem Language Result Execution time Memory
442172 2021-07-07T09:01:49 Z Haidara Mecho (IOI09_mecho) C++17
20 / 100
416 ms 12620 KB
/* * * * * * * * * *\
 * Author: Haidara *
 * LANG: C++17     *
 * PROB:           *
\* * * * * * * * * */
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define rep(i,x,n) for(int i=x;i<(n);i++)
#define FOR(i,n) rep(i,0,n)
#define per(i,x,n) for(int i=x;i>(n);i--)
#define ROF(i,x) for(int i=x;i>=0;i--)
#define v(i) vector< i >
#define p(i,j) pair< i , j >
#define pii pair<int,int>
#define m(i,j) map< i , j >
#define um(i,j) unordered_map< i , j >
#define pq(i) priority_queue< i >
#define ff first
#define all(x) x.begin(),x.end()
#define ss second
#define pp push_back
using namespace std;
void SIO(string name="")
{
    if(name!="")
    {
        freopen((name+".in").c_str(),"r",stdin);
        freopen((name+".out").c_str(),"w",stdout);
    }
}
const int inf=1LL<<60LL;
const int mod=1e9+7;
const int maxn=808;
int n,foot;
pii Mecho,House;
char a[maxn][maxn];
bool vis[maxn][maxn];
queue<pii>q;
v(v(int)) dist;
int dx[] {-1,1,0,0};
int dy[] {0,0,-1,1};
bool valid(int x,int y)
{
    return x>=0&&y>=0&&x<n&&y<n&&a[x][y]=='G';
}
bool nvalid(int x,int y)
{
    return x>=0&&y>=0&&x<n&&y<n;
}
bool check(int Time)
{
    v(v(int))newdist;
    newdist=dist;
    FOR(i,maxn)
    FOR(j,maxn)
    {
        vis[i][j]=0;
        if(a[i][j]=='T'||a[i][j]=='H'||a[i][j]=='M')
            vis[i][j]=1;
    }
    queue<p(pii,int)>nq;
    nq.push({Mecho,foot});
    newdist[Mecho.ff][Mecho.ss]=Time;
    while(nq.size())
    {
        pii f=nq.front().ff;
        int lft=nq.front().ss;
        nq.pop();
        FOR(i,4)
        {
            int x=f.ff+dx[i],y=f.ss+dy[i];
            if(nvalid(x,y)&&(a[x][y]=='G'||a[x][y]=='D'))
            {
                if(!vis[x][y])
                {
                    if(lft)
                    {
                        if(newdist[x][y]>newdist[f.ff][f.ss])
                        {
                            newdist[x][y]=newdist[f.ff][f.ss];
                            nq.push({{x,y},lft-1});
                            vis[x][y]=1;
                        }
                    }
                    else
                    {
                        if(newdist[x][y]>newdist[f.ff][f.ss]+1)
                        {
                            newdist[x][y]=newdist[f.ff][f.ss];
                            nq.push({{x,y},foot});
                            vis[x][y]=1;
                        }
                    }
                }
            }
        }
    }
    return newdist[House.ff][House.ss]!=inf;
}
void solve()
{
    while(q.size())
    {
        pii f=q.front();
        q.pop();
        FOR(i,4)
        {
            int x=f.ff+dx[i],y=f.ss+dy[i];
            if(valid(x,y))
            {
                if(!vis[x][y])
                {
                    vis[x][y]=1;
                    q.push({x,y});
                    dist[x][y]=dist[f.ff][f.ss]+1;
                }
                else if(dist[x][y]>dist[f.ff][f.ss]+1)
                {
                    dist[x][y]=dist[f.ff][f.ss]+1;
                    q.push({x,y});
                }
            }
        }
    }
}
signed main()
{
    SIO("");
    cin>>n>>foot;
    dist.resize(maxn);
    FOR(i,maxn)
    dist[i].resize(maxn);
    FOR(i,n)
    FOR(j,n)
    {
        cin>>a[i][j];
        dist[i][j]=inf;
        if(a[i][j]=='M')
            Mecho= {i,j};
        else if(a[i][j]=='H')
            q.push({i,j}),vis[i][j]=1,dist[i][j]=0;
        else if(a[i][j]=='T')
            vis[i][j]=1;
        else if(a[i][j]=='D')
        House={i,j};
    }
    solve();
    int l=1,r=800*800,ans=0;
    while(l<=r)
    {
        int mid=l+(r-l)/2;
        if(check(mid))
            ans=max(ans,mid),l=mid+1;
        else
            r=mid-1;
    }
    cout<<ans-1;
}

Compilation message

mecho.cpp: In function 'void SIO(std::string)':
mecho.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen((name+".in").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mecho.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen((name+".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 38 ms 11212 KB Output is correct
2 Incorrect 37 ms 11212 KB Output isn't correct
3 Correct 37 ms 11208 KB Output is correct
4 Correct 41 ms 11140 KB Output is correct
5 Incorrect 48 ms 11212 KB Output isn't correct
6 Incorrect 44 ms 11224 KB Output isn't correct
7 Incorrect 279 ms 12432 KB Output isn't correct
8 Incorrect 41 ms 11212 KB Output isn't correct
9 Incorrect 51 ms 11204 KB Output isn't correct
10 Incorrect 43 ms 11220 KB Output isn't correct
11 Incorrect 49 ms 11212 KB Output isn't correct
12 Incorrect 40 ms 11260 KB Output isn't correct
13 Correct 73 ms 11280 KB Output is correct
14 Incorrect 82 ms 11324 KB Output isn't correct
15 Correct 40 ms 11216 KB Output is correct
16 Incorrect 42 ms 11212 KB Output isn't correct
17 Correct 44 ms 11212 KB Output is correct
18 Correct 41 ms 11232 KB Output is correct
19 Correct 37 ms 11224 KB Output is correct
20 Incorrect 39 ms 11212 KB Output isn't correct
21 Correct 49 ms 11236 KB Output is correct
22 Incorrect 50 ms 11228 KB Output isn't correct
23 Correct 39 ms 11260 KB Output is correct
24 Incorrect 41 ms 11244 KB Output isn't correct
25 Correct 40 ms 11212 KB Output is correct
26 Incorrect 41 ms 11264 KB Output isn't correct
27 Correct 46 ms 11276 KB Output is correct
28 Correct 44 ms 11256 KB Output is correct
29 Correct 42 ms 11276 KB Output is correct
30 Incorrect 52 ms 11200 KB Output isn't correct
31 Correct 40 ms 11212 KB Output is correct
32 Correct 38 ms 11280 KB Output is correct
33 Correct 54 ms 11596 KB Output is correct
34 Incorrect 53 ms 11516 KB Output isn't correct
35 Incorrect 98 ms 11656 KB Output isn't correct
36 Correct 55 ms 11672 KB Output is correct
37 Incorrect 56 ms 11684 KB Output isn't correct
38 Incorrect 109 ms 11724 KB Output isn't correct
39 Correct 61 ms 11844 KB Output is correct
40 Incorrect 57 ms 11724 KB Output isn't correct
41 Incorrect 120 ms 11816 KB Output isn't correct
42 Correct 63 ms 11844 KB Output is correct
43 Incorrect 61 ms 11852 KB Output isn't correct
44 Incorrect 139 ms 11972 KB Output isn't correct
45 Correct 66 ms 11852 KB Output is correct
46 Incorrect 67 ms 11932 KB Output isn't correct
47 Incorrect 163 ms 12020 KB Output isn't correct
48 Correct 72 ms 12032 KB Output is correct
49 Incorrect 73 ms 11972 KB Output isn't correct
50 Incorrect 177 ms 12104 KB Output isn't correct
51 Correct 77 ms 12112 KB Output is correct
52 Incorrect 81 ms 12100 KB Output isn't correct
53 Incorrect 201 ms 12208 KB Output isn't correct
54 Correct 82 ms 12128 KB Output is correct
55 Incorrect 86 ms 12168 KB Output isn't correct
56 Incorrect 274 ms 12360 KB Output isn't correct
57 Correct 91 ms 12228 KB Output is correct
58 Incorrect 91 ms 12300 KB Output isn't correct
59 Incorrect 276 ms 12388 KB Output isn't correct
60 Correct 106 ms 12316 KB Output is correct
61 Incorrect 103 ms 12276 KB Output isn't correct
62 Incorrect 284 ms 12404 KB Output isn't correct
63 Incorrect 369 ms 12424 KB Output isn't correct
64 Correct 384 ms 12364 KB Output is correct
65 Incorrect 416 ms 12392 KB Output isn't correct
66 Incorrect 348 ms 12356 KB Output isn't correct
67 Incorrect 368 ms 12364 KB Output isn't correct
68 Incorrect 253 ms 12372 KB Output isn't correct
69 Incorrect 213 ms 12564 KB Output isn't correct
70 Incorrect 212 ms 12396 KB Output isn't correct
71 Incorrect 209 ms 12484 KB Output isn't correct
72 Incorrect 228 ms 12404 KB Output isn't correct
73 Incorrect 183 ms 12464 KB Output isn't correct
74 Correct 190 ms 12468 KB Output is correct
75 Incorrect 187 ms 12444 KB Output isn't correct
76 Incorrect 176 ms 12412 KB Output isn't correct
77 Incorrect 198 ms 12592 KB Output isn't correct
78 Incorrect 203 ms 12580 KB Output isn't correct
79 Correct 173 ms 12484 KB Output is correct
80 Incorrect 169 ms 12496 KB Output isn't correct
81 Incorrect 181 ms 12464 KB Output isn't correct
82 Incorrect 207 ms 12420 KB Output isn't correct
83 Incorrect 245 ms 12436 KB Output isn't correct
84 Correct 208 ms 12456 KB Output is correct
85 Incorrect 194 ms 12428 KB Output isn't correct
86 Incorrect 208 ms 12464 KB Output isn't correct
87 Incorrect 226 ms 12436 KB Output isn't correct
88 Incorrect 227 ms 12468 KB Output isn't correct
89 Correct 233 ms 12464 KB Output is correct
90 Incorrect 232 ms 12620 KB Output isn't correct
91 Incorrect 232 ms 12436 KB Output isn't correct
92 Incorrect 226 ms 12432 KB Output isn't correct