답안 #442332

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442332 2021-07-07T13:11:25 Z Haidara Mecho (IOI09_mecho) C++17
4 / 100
78 ms 7200 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};
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(x<0||y<0||x>=n||y>=n||dist[x][y]!=inf||a[x][y]!='G')
                continue;
            dist[x][y]=dist[f.ff][f.ss]+jump;
            q.push({x,y});
        }
    }
}
bool check(int st)
{
    queue<p(pii,int)>qq;
    if(st*jump>=dist[M.ff][M.ss])
        return 0;
    bool vis[maxn][maxn];
    FOR(i,maxn)
    FOR(j,maxn)
    vis[i][j]=0;
    qq.push({M,st*jump});
    vis[M.ff][M.ss]=1;
    while(qq.size())
    {
        pii f=qq.front().ff;
        int curr=qq.front().ss;
        qq.pop();
        if(f==D)
            return 1;
        FOR(i,4){
            int x=f.ff+dx[i],y=f.ss+dy[i];
            if(x>=0||y>=0||x<n||y<n||a[x][y]=='T'||vis[x][y]||dist[x][y]<=curr+1)
                continue;
            qq.push({{x,y},curr+1});
            vis[x][y]=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=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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 844 KB Output isn't correct
2 Incorrect 2 ms 844 KB Output isn't correct
3 Incorrect 3 ms 844 KB Output isn't correct
4 Incorrect 3 ms 844 KB Output isn't correct
5 Incorrect 2 ms 844 KB Output isn't correct
6 Incorrect 2 ms 972 KB Output isn't correct
7 Incorrect 76 ms 6780 KB Output isn't correct
8 Correct 2 ms 972 KB Output is correct
9 Incorrect 2 ms 972 KB Output isn't correct
10 Incorrect 2 ms 972 KB Output isn't correct
11 Incorrect 2 ms 972 KB Output isn't correct
12 Incorrect 3 ms 1228 KB Output isn't correct
13 Incorrect 3 ms 1100 KB Output isn't correct
14 Correct 3 ms 1228 KB Output is correct
15 Incorrect 2 ms 972 KB Output isn't correct
16 Incorrect 2 ms 972 KB Output isn't correct
17 Incorrect 2 ms 972 KB Output isn't correct
18 Incorrect 2 ms 972 KB Output isn't correct
19 Incorrect 2 ms 972 KB Output isn't correct
20 Incorrect 2 ms 972 KB Output isn't correct
21 Incorrect 2 ms 1144 KB Output isn't correct
22 Incorrect 2 ms 1100 KB Output isn't correct
23 Incorrect 3 ms 1100 KB Output isn't correct
24 Incorrect 2 ms 1100 KB Output isn't correct
25 Incorrect 3 ms 1228 KB Output isn't correct
26 Incorrect 3 ms 1228 KB Output isn't correct
27 Incorrect 3 ms 1228 KB Output isn't correct
28 Incorrect 3 ms 1228 KB Output isn't correct
29 Incorrect 3 ms 1228 KB Output isn't correct
30 Incorrect 3 ms 1228 KB Output isn't correct
31 Incorrect 3 ms 1228 KB Output isn't correct
32 Incorrect 3 ms 1228 KB Output isn't correct
33 Incorrect 12 ms 3404 KB Output isn't correct
34 Incorrect 12 ms 3300 KB Output isn't correct
35 Incorrect 13 ms 3436 KB Output isn't correct
36 Incorrect 15 ms 3772 KB Output isn't correct
37 Incorrect 16 ms 3780 KB Output isn't correct
38 Incorrect 19 ms 3792 KB Output isn't correct
39 Incorrect 18 ms 4044 KB Output isn't correct
40 Incorrect 18 ms 4044 KB Output isn't correct
41 Incorrect 21 ms 4044 KB Output isn't correct
42 Incorrect 23 ms 4420 KB Output isn't correct
43 Incorrect 22 ms 4424 KB Output isn't correct
44 Incorrect 26 ms 4372 KB Output isn't correct
45 Incorrect 26 ms 4764 KB Output isn't correct
46 Incorrect 27 ms 4772 KB Output isn't correct
47 Incorrect 29 ms 4788 KB Output isn't correct
48 Incorrect 31 ms 5188 KB Output isn't correct
49 Incorrect 29 ms 5144 KB Output isn't correct
50 Incorrect 37 ms 5072 KB Output isn't correct
51 Incorrect 35 ms 5440 KB Output isn't correct
52 Incorrect 36 ms 5544 KB Output isn't correct
53 Incorrect 40 ms 5520 KB Output isn't correct
54 Incorrect 40 ms 5828 KB Output isn't correct
55 Incorrect 39 ms 5852 KB Output isn't correct
56 Incorrect 48 ms 5796 KB Output isn't correct
57 Incorrect 46 ms 6200 KB Output isn't correct
58 Incorrect 45 ms 6196 KB Output isn't correct
59 Incorrect 53 ms 6340 KB Output isn't correct
60 Incorrect 51 ms 6564 KB Output isn't correct
61 Incorrect 51 ms 6596 KB Output isn't correct
62 Incorrect 61 ms 6612 KB Output isn't correct
63 Incorrect 72 ms 6596 KB Output isn't correct
64 Incorrect 71 ms 6548 KB Output isn't correct
65 Incorrect 73 ms 6596 KB Output isn't correct
66 Incorrect 62 ms 6564 KB Output isn't correct
67 Correct 61 ms 6596 KB Output is correct
68 Incorrect 72 ms 6636 KB Output isn't correct
69 Incorrect 65 ms 6620 KB Output isn't correct
70 Incorrect 78 ms 6596 KB Output isn't correct
71 Incorrect 75 ms 6544 KB Output isn't correct
72 Incorrect 67 ms 6568 KB Output isn't correct
73 Incorrect 65 ms 7160 KB Output isn't correct
74 Incorrect 78 ms 7108 KB Output isn't correct
75 Incorrect 65 ms 7108 KB Output isn't correct
76 Incorrect 69 ms 7068 KB Output isn't correct
77 Incorrect 68 ms 7200 KB Output isn't correct
78 Correct 67 ms 7004 KB Output is correct
79 Incorrect 66 ms 6968 KB Output isn't correct
80 Incorrect 66 ms 7112 KB Output isn't correct
81 Incorrect 64 ms 7008 KB Output isn't correct
82 Incorrect 65 ms 6980 KB Output isn't correct
83 Incorrect 64 ms 7036 KB Output isn't correct
84 Incorrect 65 ms 7052 KB Output isn't correct
85 Incorrect 64 ms 7012 KB Output isn't correct
86 Incorrect 66 ms 6972 KB Output isn't correct
87 Incorrect 67 ms 6984 KB Output isn't correct
88 Incorrect 63 ms 6912 KB Output isn't correct
89 Incorrect 65 ms 6820 KB Output isn't correct
90 Incorrect 64 ms 6896 KB Output isn't correct
91 Incorrect 64 ms 6896 KB Output isn't correct
92 Incorrect 64 ms 7000 KB Output isn't correct