Submission #442314

# Submission time Handle Problem Language Result Execution time Memory
442314 2021-07-07T12:35:35 Z Haidara Mecho (IOI09_mecho) C++17
12 / 100
256 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]+jump<dist[x][y])
                dist[x][y]=dist[f.ff][f.ss]+jump,q.push({x,y});
        }
    }
}
bool check(int st)
{
    queue<p(pii,int)>qq;
    qq.push({M,st*jump});
    while(qq.size())
    {
        pii f=qq.front().ff;
        int 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(dist[x][y]>curr+1)
                    qq.push({{x,y},curr+1});
            }
        }
    }
    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 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Correct 0 ms 204 KB Output is correct
4 Incorrect 1 ms 332 KB Output isn't correct
5 Incorrect 0 ms 332 KB Output isn't correct
6 Incorrect 103 ms 21220 KB Output isn't correct
7 Runtime error 142 ms 65536 KB Execution killed with signal 9
8 Correct 1 ms 332 KB Output is correct
9 Runtime error 88 ms 65540 KB Execution killed with signal 9
10 Correct 1 ms 460 KB Output is correct
11 Runtime error 97 ms 65540 KB Execution killed with signal 9
12 Incorrect 1 ms 588 KB Output isn't correct
13 Runtime error 92 ms 65540 KB Execution killed with signal 9
14 Runtime error 86 ms 65540 KB Execution killed with signal 9
15 Correct 1 ms 332 KB Output is correct
16 Runtime error 130 ms 65540 KB Execution killed with signal 9
17 Correct 0 ms 332 KB Output is correct
18 Runtime error 127 ms 65540 KB Execution killed with signal 9
19 Correct 1 ms 460 KB Output is correct
20 Runtime error 128 ms 65540 KB Execution killed with signal 9
21 Correct 1 ms 460 KB Output is correct
22 Runtime error 125 ms 65540 KB Execution killed with signal 9
23 Correct 1 ms 460 KB Output is correct
24 Runtime error 123 ms 65540 KB Execution killed with signal 9
25 Correct 1 ms 588 KB Output is correct
26 Runtime error 156 ms 65540 KB Execution killed with signal 9
27 Correct 1 ms 588 KB Output is correct
28 Runtime error 125 ms 65536 KB Execution killed with signal 9
29 Correct 1 ms 588 KB Output is correct
30 Runtime error 121 ms 65540 KB Execution killed with signal 9
31 Correct 1 ms 588 KB Output is correct
32 Runtime error 121 ms 65540 KB Execution killed with signal 9
33 Correct 11 ms 2764 KB Output is correct
34 Runtime error 125 ms 65540 KB Execution killed with signal 9
35 Runtime error 122 ms 65536 KB Execution killed with signal 9
36 Correct 14 ms 3148 KB Output is correct
37 Runtime error 140 ms 65540 KB Execution killed with signal 9
38 Runtime error 127 ms 65540 KB Execution killed with signal 9
39 Correct 18 ms 3496 KB Output is correct
40 Runtime error 139 ms 65540 KB Execution killed with signal 9
41 Runtime error 124 ms 65536 KB Execution killed with signal 9
42 Correct 20 ms 3788 KB Output is correct
43 Runtime error 139 ms 65540 KB Execution killed with signal 9
44 Runtime error 131 ms 65540 KB Execution killed with signal 9
45 Correct 24 ms 4224 KB Output is correct
46 Runtime error 134 ms 65540 KB Execution killed with signal 9
47 Runtime error 135 ms 65540 KB Execution killed with signal 9
48 Correct 32 ms 4516 KB Output is correct
49 Runtime error 142 ms 65540 KB Execution killed with signal 9
50 Runtime error 142 ms 65540 KB Execution killed with signal 9
51 Correct 37 ms 5032 KB Output is correct
52 Runtime error 144 ms 65540 KB Execution killed with signal 9
53 Runtime error 142 ms 65540 KB Execution killed with signal 9
54 Correct 45 ms 5156 KB Output is correct
55 Runtime error 149 ms 65540 KB Execution killed with signal 9
56 Runtime error 173 ms 65540 KB Execution killed with signal 9
57 Correct 46 ms 5568 KB Output is correct
58 Runtime error 187 ms 65540 KB Execution killed with signal 9
59 Runtime error 149 ms 65540 KB Execution killed with signal 9
60 Correct 50 ms 5908 KB Output is correct
61 Runtime error 164 ms 65536 KB Execution killed with signal 9
62 Runtime error 195 ms 65540 KB Execution killed with signal 9
63 Runtime error 169 ms 65540 KB Execution killed with signal 9
64 Runtime error 170 ms 65540 KB Execution killed with signal 9
65 Runtime error 194 ms 65540 KB Execution killed with signal 9
66 Runtime error 173 ms 65540 KB Execution killed with signal 9
67 Runtime error 167 ms 65540 KB Execution killed with signal 9
68 Runtime error 205 ms 65536 KB Execution killed with signal 9
69 Runtime error 171 ms 65540 KB Execution killed with signal 9
70 Runtime error 169 ms 65540 KB Execution killed with signal 9
71 Runtime error 183 ms 65540 KB Execution killed with signal 9
72 Runtime error 175 ms 65536 KB Execution killed with signal 9
73 Runtime error 147 ms 65536 KB Execution killed with signal 9
74 Runtime error 164 ms 65540 KB Execution killed with signal 9
75 Runtime error 140 ms 65540 KB Execution killed with signal 9
76 Runtime error 144 ms 65540 KB Execution killed with signal 9
77 Runtime error 150 ms 65540 KB Execution killed with signal 9
78 Runtime error 143 ms 65536 KB Execution killed with signal 9
79 Runtime error 140 ms 65536 KB Execution killed with signal 9
80 Runtime error 146 ms 65540 KB Execution killed with signal 9
81 Runtime error 170 ms 65540 KB Execution killed with signal 9
82 Runtime error 150 ms 65540 KB Execution killed with signal 9
83 Runtime error 142 ms 65536 KB Execution killed with signal 9
84 Runtime error 145 ms 65540 KB Execution killed with signal 9
85 Runtime error 256 ms 65536 KB Execution killed with signal 9
86 Runtime error 145 ms 65540 KB Execution killed with signal 9
87 Runtime error 149 ms 65540 KB Execution killed with signal 9
88 Runtime error 144 ms 65540 KB Execution killed with signal 9
89 Runtime error 139 ms 65540 KB Execution killed with signal 9
90 Runtime error 140 ms 65540 KB Execution killed with signal 9
91 Runtime error 163 ms 65540 KB Execution killed with signal 9
92 Runtime error 151 ms 65540 KB Execution killed with signal 9