Submission #442310

# Submission time Handle Problem Language Result Execution time Memory
442310 2021-07-07T12:28:16 Z Haidara Mecho (IOI09_mecho) C++17
1 / 100
497 ms 65540 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;
char a[maxn][maxn];
int n,jump;
pii M,D;
queue<pii>q;
int dist[maxn][maxn],dx[] {-1,1,0,0},dy[] {0,0,1,-1};
bool valid(int x,int y)
{
    return x>=0&&y>=0&&x<n&&y<n&&a[x][y]!='T';
}
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)&&dist[f.ff][f.ss]+1<dist[x][y])
                dist[x][y]=dist[f.ff][f.ss]+1,q.push({x,y});
        }
    }
}
bool check(int st)
{
    queue<p(pii,pii)>qq;
    qq.push({M,{st,jump}});
    while(qq.size())
    {
        pii f=qq.front().ff;
        pii curr=qq.front().ss;
        qq.pop();
        if(f==D)
        {
            while(qq.size())
                qq.pop();
            return 1;
        }
        FOR(i,4)
        {
            int x=f.ff+dx[i],y=f.ss+dy[i];
            if(valid(x,y))
            {
                if(curr.ss)
                {
                    if(dist[x][y]>curr.ff)
                        qq.push({{x,y},{curr.ff,curr.ss-1}});
                }
                else
                {
                    if(dist[x][y]>curr.ff+1)
                        qq.push({{x,y},{curr.ff+1,jump}});
                }
            }
        }
    }
    return 0;
}
signed main()
{
    SIO("");
    cin>>n>>jump;
    FOR(i,n)
    FOR(j,n)
    {
        dist[i][j]=inf;
        cin>>a[i][j];
        if(a[i][j]=='M')
        {
            M= {i,j};
        }
        else if(a[i][j]=='D')
        {
            D= {i,j};
        }
        else if(a[i][j]=='H')
        {
            q.push({i,j});
            dist[i][j]=0;
        }
    }
    solve();
    int l=1,r=maxn*maxn*2,ans=-1;
    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;
}

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 Incorrect 1 ms 204 KB Output isn't correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Incorrect 0 ms 204 KB Output isn't correct
5 Incorrect 1 ms 332 KB Output isn't correct
6 Runtime error 122 ms 65540 KB Execution killed with signal 9
7 Runtime error 130 ms 65540 KB Execution killed with signal 9
8 Incorrect 2 ms 588 KB Output isn't correct
9 Runtime error 81 ms 65536 KB Execution killed with signal 9
10 Incorrect 107 ms 51416 KB Output isn't correct
11 Runtime error 82 ms 65540 KB Execution killed with signal 9
12 Runtime error 132 ms 65536 KB Execution killed with signal 9
13 Runtime error 81 ms 65540 KB Execution killed with signal 9
14 Runtime error 80 ms 65536 KB Execution killed with signal 9
15 Incorrect 235 ms 64752 KB Output isn't correct
16 Runtime error 111 ms 65540 KB Execution killed with signal 9
17 Runtime error 152 ms 65540 KB Execution killed with signal 9
18 Runtime error 102 ms 65540 KB Execution killed with signal 9
19 Runtime error 126 ms 65540 KB Execution killed with signal 9
20 Runtime error 100 ms 65540 KB Execution killed with signal 9
21 Runtime error 128 ms 65540 KB Execution killed with signal 9
22 Runtime error 106 ms 65540 KB Execution killed with signal 9
23 Runtime error 124 ms 65536 KB Execution killed with signal 9
24 Runtime error 101 ms 65540 KB Execution killed with signal 9
25 Runtime error 126 ms 65540 KB Execution killed with signal 9
26 Runtime error 102 ms 65540 KB Execution killed with signal 9
27 Runtime error 126 ms 65536 KB Execution killed with signal 9
28 Runtime error 106 ms 65540 KB Execution killed with signal 9
29 Runtime error 128 ms 65540 KB Execution killed with signal 9
30 Runtime error 99 ms 65540 KB Execution killed with signal 9
31 Runtime error 129 ms 65540 KB Execution killed with signal 9
32 Runtime error 101 ms 65540 KB Execution killed with signal 9
33 Runtime error 138 ms 65540 KB Execution killed with signal 9
34 Runtime error 108 ms 65540 KB Execution killed with signal 9
35 Runtime error 113 ms 65540 KB Execution killed with signal 9
36 Runtime error 135 ms 65540 KB Execution killed with signal 9
37 Runtime error 129 ms 65540 KB Execution killed with signal 9
38 Runtime error 112 ms 65540 KB Execution killed with signal 9
39 Runtime error 137 ms 65540 KB Execution killed with signal 9
40 Runtime error 132 ms 65540 KB Execution killed with signal 9
41 Runtime error 111 ms 65536 KB Execution killed with signal 9
42 Runtime error 138 ms 65540 KB Execution killed with signal 9
43 Runtime error 121 ms 65536 KB Execution killed with signal 9
44 Runtime error 122 ms 65540 KB Execution killed with signal 9
45 Runtime error 149 ms 65540 KB Execution killed with signal 9
46 Runtime error 141 ms 65540 KB Execution killed with signal 9
47 Runtime error 119 ms 65540 KB Execution killed with signal 9
48 Runtime error 147 ms 65540 KB Execution killed with signal 9
49 Runtime error 126 ms 65540 KB Execution killed with signal 9
50 Runtime error 125 ms 65540 KB Execution killed with signal 9
51 Runtime error 150 ms 65540 KB Execution killed with signal 9
52 Runtime error 124 ms 65540 KB Execution killed with signal 9
53 Runtime error 127 ms 65540 KB Execution killed with signal 9
54 Runtime error 153 ms 65540 KB Execution killed with signal 9
55 Runtime error 152 ms 65540 KB Execution killed with signal 9
56 Runtime error 137 ms 65540 KB Execution killed with signal 9
57 Runtime error 165 ms 65540 KB Execution killed with signal 9
58 Runtime error 166 ms 65540 KB Execution killed with signal 9
59 Runtime error 146 ms 65540 KB Execution killed with signal 9
60 Runtime error 167 ms 65540 KB Execution killed with signal 9
61 Runtime error 152 ms 65540 KB Execution killed with signal 9
62 Runtime error 146 ms 65540 KB Execution killed with signal 9
63 Runtime error 153 ms 65540 KB Execution killed with signal 9
64 Runtime error 150 ms 65540 KB Execution killed with signal 9
65 Runtime error 151 ms 65540 KB Execution killed with signal 9
66 Runtime error 151 ms 65540 KB Execution killed with signal 9
67 Runtime error 149 ms 65540 KB Execution killed with signal 9
68 Runtime error 159 ms 65540 KB Execution killed with signal 9
69 Runtime error 174 ms 65540 KB Execution killed with signal 9
70 Runtime error 164 ms 65540 KB Execution killed with signal 9
71 Runtime error 164 ms 65540 KB Execution killed with signal 9
72 Runtime error 186 ms 65540 KB Execution killed with signal 9
73 Runtime error 130 ms 65540 KB Execution killed with signal 9
74 Runtime error 136 ms 65540 KB Execution killed with signal 9
75 Runtime error 139 ms 65540 KB Execution killed with signal 9
76 Runtime error 131 ms 65536 KB Execution killed with signal 9
77 Runtime error 133 ms 65536 KB Execution killed with signal 9
78 Runtime error 149 ms 65536 KB Execution killed with signal 9
79 Runtime error 136 ms 65540 KB Execution killed with signal 9
80 Runtime error 132 ms 65540 KB Execution killed with signal 9
81 Runtime error 131 ms 65540 KB Execution killed with signal 9
82 Runtime error 137 ms 65536 KB Execution killed with signal 9
83 Runtime error 153 ms 65540 KB Execution killed with signal 9
84 Runtime error 134 ms 65540 KB Execution killed with signal 9
85 Runtime error 497 ms 65540 KB Execution killed with signal 9
86 Runtime error 136 ms 65536 KB Execution killed with signal 9
87 Runtime error 139 ms 65540 KB Execution killed with signal 9
88 Runtime error 132 ms 65536 KB Execution killed with signal 9
89 Runtime error 154 ms 65540 KB Execution killed with signal 9
90 Runtime error 130 ms 65536 KB Execution killed with signal 9
91 Runtime error 154 ms 65540 KB Execution killed with signal 9
92 Runtime error 129 ms 65540 KB Execution killed with signal 9