답안 #442336

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
442336 2021-07-07T13:16:18 Z Haidara Mecho (IOI09_mecho) C++17
5 / 100
336 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<<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'&&a[x][y]!='H';
}
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&&a[x][y]=='G'&&dist[x][y]==inf)
                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;
    qq.push({M,st*jump});
    bool vis[maxn][maxn];
    FOR(i,maxn)
    FOR(j,maxn)
    vis[i][j]=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)
            return 1;
        FOR(i,4)
        {
            int x=f.ff+dx[i],y=f.ss+dy[i];
            if(!valid(x,y)||dist[x][y]<=curr+1&&vis[x][y])
                continue;
            qq.push({{x,y},curr+1}),vis[x][y]=1;
        }
    }
    return 0;
}
signed main()
{
    SIO("");
    cin>>n>>jump;
    FOR(i,n)
    {
        cin>>ws;
        FOR(j,n)
        {
            dist[i][j]=inf;
            cin>>a[i][j];
            if(a[i][j]=='M')
                M= {i,j},a[i][j]='G';
            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 'bool check(long long int)':
mecho.cpp:79:47: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   79 |             if(!valid(x,y)||dist[x][y]<=curr+1&&vis[x][y])
      |                             ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
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 1 ms 844 KB Output isn't correct
2 Incorrect 1 ms 844 KB Output isn't correct
3 Incorrect 1 ms 844 KB Output isn't correct
4 Incorrect 1 ms 844 KB Output isn't correct
5 Incorrect 1 ms 972 KB Output isn't correct
6 Incorrect 1 ms 972 KB Output isn't correct
7 Runtime error 144 ms 65540 KB Execution killed with signal 9
8 Incorrect 1 ms 972 KB Output isn't correct
9 Runtime error 95 ms 65540 KB Execution killed with signal 9
10 Incorrect 1 ms 972 KB Output isn't correct
11 Runtime error 107 ms 65540 KB Execution killed with signal 9
12 Correct 1 ms 1228 KB Output is correct
13 Incorrect 1 ms 1100 KB Output isn't correct
14 Runtime error 96 ms 65536 KB Execution killed with signal 9
15 Incorrect 1 ms 972 KB Output isn't correct
16 Runtime error 134 ms 65540 KB Execution killed with signal 9
17 Incorrect 1 ms 972 KB Output isn't correct
18 Runtime error 133 ms 65536 KB Execution killed with signal 9
19 Incorrect 1 ms 972 KB Output isn't correct
20 Runtime error 131 ms 65540 KB Execution killed with signal 9
21 Incorrect 1 ms 1100 KB Output isn't correct
22 Runtime error 135 ms 65540 KB Execution killed with signal 9
23 Incorrect 1 ms 1100 KB Output isn't correct
24 Runtime error 129 ms 65540 KB Execution killed with signal 9
25 Incorrect 1 ms 1228 KB Output isn't correct
26 Runtime error 133 ms 65540 KB Execution killed with signal 9
27 Incorrect 1 ms 1228 KB Output isn't correct
28 Runtime error 131 ms 65540 KB Execution killed with signal 9
29 Incorrect 2 ms 1228 KB Output isn't correct
30 Runtime error 128 ms 65540 KB Execution killed with signal 9
31 Incorrect 2 ms 1228 KB Output isn't correct
32 Runtime error 127 ms 65540 KB Execution killed with signal 9
33 Incorrect 11 ms 3380 KB Output isn't correct
34 Runtime error 137 ms 65540 KB Execution killed with signal 9
35 Runtime error 130 ms 65540 KB Execution killed with signal 9
36 Incorrect 14 ms 3660 KB Output isn't correct
37 Runtime error 142 ms 65540 KB Execution killed with signal 9
38 Runtime error 131 ms 65536 KB Execution killed with signal 9
39 Incorrect 17 ms 4036 KB Output isn't correct
40 Runtime error 136 ms 65540 KB Execution killed with signal 9
41 Runtime error 133 ms 65540 KB Execution killed with signal 9
42 Incorrect 20 ms 4484 KB Output isn't correct
43 Runtime error 153 ms 65540 KB Execution killed with signal 9
44 Runtime error 137 ms 65540 KB Execution killed with signal 9
45 Incorrect 25 ms 4812 KB Output isn't correct
46 Runtime error 146 ms 65540 KB Execution killed with signal 9
47 Runtime error 141 ms 65540 KB Execution killed with signal 9
48 Incorrect 29 ms 5060 KB Output isn't correct
49 Runtime error 156 ms 65540 KB Execution killed with signal 9
50 Runtime error 146 ms 65540 KB Execution killed with signal 9
51 Incorrect 33 ms 5492 KB Output isn't correct
52 Runtime error 154 ms 65540 KB Execution killed with signal 9
53 Runtime error 150 ms 65540 KB Execution killed with signal 9
54 Incorrect 38 ms 5792 KB Output isn't correct
55 Runtime error 164 ms 65540 KB Execution killed with signal 9
56 Runtime error 153 ms 65540 KB Execution killed with signal 9
57 Incorrect 45 ms 6212 KB Output isn't correct
58 Runtime error 164 ms 65540 KB Execution killed with signal 9
59 Runtime error 163 ms 65540 KB Execution killed with signal 9
60 Incorrect 49 ms 6520 KB Output isn't correct
61 Runtime error 174 ms 65540 KB Execution killed with signal 9
62 Runtime error 170 ms 65540 KB Execution killed with signal 9
63 Runtime error 179 ms 65540 KB Execution killed with signal 9
64 Runtime error 184 ms 65540 KB Execution killed with signal 9
65 Runtime error 177 ms 65540 KB Execution killed with signal 9
66 Runtime error 181 ms 65540 KB Execution killed with signal 9
67 Runtime error 180 ms 65540 KB Execution killed with signal 9
68 Runtime error 178 ms 65540 KB Execution killed with signal 9
69 Runtime error 178 ms 65540 KB Execution killed with signal 9
70 Runtime error 181 ms 65540 KB Execution killed with signal 9
71 Runtime error 181 ms 65536 KB Execution killed with signal 9
72 Runtime error 178 ms 65540 KB Execution killed with signal 9
73 Runtime error 148 ms 65540 KB Execution killed with signal 9
74 Runtime error 146 ms 65536 KB Execution killed with signal 9
75 Runtime error 145 ms 65540 KB Execution killed with signal 9
76 Runtime error 149 ms 65540 KB Execution killed with signal 9
77 Runtime error 146 ms 65540 KB Execution killed with signal 9
78 Runtime error 146 ms 65536 KB Execution killed with signal 9
79 Runtime error 153 ms 65540 KB Execution killed with signal 9
80 Runtime error 145 ms 65540 KB Execution killed with signal 9
81 Runtime error 145 ms 65540 KB Execution killed with signal 9
82 Runtime error 149 ms 65540 KB Execution killed with signal 9
83 Runtime error 150 ms 65540 KB Execution killed with signal 9
84 Runtime error 144 ms 65540 KB Execution killed with signal 9
85 Runtime error 336 ms 65540 KB Execution killed with signal 9
86 Runtime error 144 ms 65536 KB Execution killed with signal 9
87 Runtime error 146 ms 65540 KB Execution killed with signal 9
88 Runtime error 146 ms 65540 KB Execution killed with signal 9
89 Runtime error 149 ms 65540 KB Execution killed with signal 9
90 Runtime error 144 ms 65540 KB Execution killed with signal 9
91 Runtime error 147 ms 65540 KB Execution killed with signal 9
92 Runtime error 144 ms 65540 KB Execution killed with signal 9