Submission #442322

# Submission time Handle Problem Language Result Execution time Memory
442322 2021-07-07T12:47:26 Z Haidara Mecho (IOI09_mecho) C++17
14 / 100
1000 ms 7216 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<<62LL;
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))
            {
                if(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});
    bool vis[maxn][maxn];
    FOR(i,maxn)
    FOR(j,maxn)
    vis[i][j]=0;
    bool ret=0;
    vis[M.ff][M.ss]=1;
    while(qq.size())
    {
        pii f=qq.front().ff;
        int curr=qq.front().ss;
        qq.pop();
        if(f==D)
            ret=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&&!vis[x][y])
                    qq.push({{x,y},curr+1}),vis[x][y]=1;
            }
        }
    }
    return ret;
}
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=0,r=inf,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 2 ms 844 KB Output is correct
2 Incorrect 2 ms 844 KB Output isn't correct
3 Correct 2 ms 844 KB Output is correct
4 Incorrect 2 ms 844 KB Output isn't correct
5 Correct 2 ms 972 KB Output is correct
6 Incorrect 2 ms 972 KB Output isn't correct
7 Incorrect 929 ms 6716 KB Output isn't correct
8 Correct 2 ms 972 KB Output is correct
9 Incorrect 3 ms 972 KB Output isn't correct
10 Correct 2 ms 972 KB Output is correct
11 Incorrect 3 ms 972 KB Output isn't correct
12 Incorrect 3 ms 1228 KB Output isn't correct
13 Incorrect 7 ms 1196 KB Output isn't correct
14 Incorrect 6 ms 1228 KB Output isn't correct
15 Correct 2 ms 972 KB Output is correct
16 Incorrect 2 ms 972 KB Output isn't correct
17 Correct 2 ms 972 KB Output is correct
18 Incorrect 3 ms 972 KB Output isn't correct
19 Correct 2 ms 972 KB Output is correct
20 Incorrect 3 ms 972 KB Output isn't correct
21 Correct 2 ms 1100 KB Output is correct
22 Incorrect 3 ms 1100 KB Output isn't correct
23 Correct 3 ms 1100 KB Output is correct
24 Incorrect 4 ms 1100 KB Output isn't correct
25 Correct 3 ms 1228 KB Output is correct
26 Incorrect 4 ms 1228 KB Output isn't correct
27 Correct 3 ms 1228 KB Output is correct
28 Incorrect 4 ms 1228 KB Output isn't correct
29 Correct 3 ms 1228 KB Output is correct
30 Incorrect 5 ms 1228 KB Output isn't correct
31 Correct 3 ms 1228 KB Output is correct
32 Incorrect 4 ms 1228 KB Output isn't correct
33 Correct 13 ms 3360 KB Output is correct
34 Incorrect 52 ms 3400 KB Output isn't correct
35 Incorrect 115 ms 3404 KB Output isn't correct
36 Correct 15 ms 3660 KB Output is correct
37 Incorrect 63 ms 3668 KB Output isn't correct
38 Incorrect 178 ms 3796 KB Output isn't correct
39 Correct 20 ms 4088 KB Output is correct
40 Incorrect 81 ms 4116 KB Output isn't correct
41 Incorrect 211 ms 4148 KB Output isn't correct
42 Correct 24 ms 4420 KB Output is correct
43 Incorrect 104 ms 4476 KB Output isn't correct
44 Incorrect 287 ms 4488 KB Output isn't correct
45 Correct 26 ms 4812 KB Output is correct
46 Incorrect 122 ms 4824 KB Output isn't correct
47 Incorrect 434 ms 4928 KB Output isn't correct
48 Correct 31 ms 5196 KB Output is correct
49 Incorrect 174 ms 5188 KB Output isn't correct
50 Incorrect 373 ms 5200 KB Output isn't correct
51 Correct 41 ms 5540 KB Output is correct
52 Incorrect 182 ms 5428 KB Output isn't correct
53 Incorrect 471 ms 5596 KB Output isn't correct
54 Correct 47 ms 5972 KB Output is correct
55 Incorrect 230 ms 5892 KB Output isn't correct
56 Incorrect 543 ms 5912 KB Output isn't correct
57 Correct 45 ms 6220 KB Output is correct
58 Incorrect 273 ms 6264 KB Output isn't correct
59 Incorrect 711 ms 6280 KB Output isn't correct
60 Correct 53 ms 6512 KB Output is correct
61 Incorrect 264 ms 6520 KB Output isn't correct
62 Incorrect 771 ms 6620 KB Output isn't correct
63 Correct 158 ms 6612 KB Output is correct
64 Incorrect 800 ms 6616 KB Output isn't correct
65 Execution timed out 1088 ms 6496 KB Time limit exceeded
66 Correct 218 ms 6604 KB Output is correct
67 Correct 175 ms 6616 KB Output is correct
68 Incorrect 922 ms 6664 KB Output isn't correct
69 Incorrect 690 ms 6724 KB Output isn't correct
70 Incorrect 643 ms 6660 KB Output isn't correct
71 Incorrect 679 ms 6600 KB Output isn't correct
72 Incorrect 541 ms 6668 KB Output isn't correct
73 Incorrect 681 ms 7164 KB Output isn't correct
74 Incorrect 316 ms 7160 KB Output isn't correct
75 Incorrect 697 ms 7164 KB Output isn't correct
76 Incorrect 514 ms 7164 KB Output isn't correct
77 Incorrect 766 ms 7108 KB Output isn't correct
78 Incorrect 811 ms 7216 KB Output isn't correct
79 Incorrect 739 ms 7180 KB Output isn't correct
80 Incorrect 775 ms 7100 KB Output isn't correct
81 Incorrect 798 ms 7108 KB Output isn't correct
82 Incorrect 729 ms 7108 KB Output isn't correct
83 Incorrect 879 ms 7028 KB Output isn't correct
84 Incorrect 750 ms 7028 KB Output isn't correct
85 Incorrect 880 ms 7024 KB Output isn't correct
86 Execution timed out 1081 ms 6984 KB Time limit exceeded
87 Incorrect 484 ms 6980 KB Output isn't correct
88 Incorrect 863 ms 6944 KB Output isn't correct
89 Incorrect 875 ms 6928 KB Output isn't correct
90 Incorrect 536 ms 6812 KB Output isn't correct
91 Incorrect 667 ms 6908 KB Output isn't correct
92 Execution timed out 1024 ms 6928 KB Time limit exceeded