답안 #773344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773344 2023-07-04T23:32:17 Z sz1218 Mecho (IOI09_mecho) C++14
95 / 100
140 ms 6316 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef pair<ll, ll> pl;
typedef pair<ll, pl> pll;
typedef vector<int> vi;

#define pb push_back
#define f first
#define s second

int __i__, __j__;
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}

#define For(i,a,b) for (int i = (a); i < (b); ++i)
#define Fir(i,a) For(i,0,a)
#define Rof(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define Rif(i,a) Rof(i,0,a)

const int NN = 805, mod = 1e9 + 7, INF = 0x3f3f3f3f;
int n, S, dism[NN][NN], disb[NN][NN], mx, my, ex, ey, dir[4][2]{{0, 1}, {0, -1}, {-1, 0}, {1, 0}}, ans;char g[NN][NN];
queue<pi> qb;

bool check(int x, int y){
    return 1 <= x && x <= n && 1 <= y && y <= n && g[x][y] != 'T';
}

void bfs(){
    while(!qb.empty()){
        auto[ux, uy] = qb.front(); qb.pop();
        For(d, 0, 4){
            int nx = ux + dir[d][0],  ny = uy + dir[d][1];
            if(check(nx, ny)){
                if(disb[nx][ny] == INF){
                    disb[nx][ny] = disb[ux][uy] + 1;
                    qb.push({nx, ny});
                }
            }
        }
    }
}

bool escapable(int delay){
    memset(dism, 0x3f, sizeof(dism));
    queue<pi> q; q.push({mx, my});dism[mx][my] = 0;
    if(delay >= disb[mx][my])return false;
    while(!q.empty()){
        auto[x, y] = q.front(); q.pop();
        For(d, 0, 4){
            int nx = x + dir[d][0], ny = y+dir[d][1];
            if(check(nx, ny)){
                if(dism[nx][ny] == INF){
                    if(nx == ex && ny == ey){
                        return true;
                    }
                    if( (dism[x][y]+1)/S < disb[nx][ny] - delay){
                        dism[nx][ny] = dism[x][y] + 1;
                        q.push({nx, ny});
                    }
                }
            }
        }
    }
    return false;
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> S;
    memset(disb, 0x3f, sizeof(disb));
    For(i, 1, n+1){
        For(j, 1, n+1){
            cin >> g[i][j];
            if(g[i][j] == 'M'){
                mx = i; my = j;
            }
            if(g[i][j] == 'H'){
                qb.push({i, j}); disb[i][j] = 0;
            }
            if(g[i][j] == 'D'){
                ex = i; ey = j;
            }
        }
    }

    bfs(); disb[ex][ey] = INF;
    int lo = 0, hi = 7e5; ans = -1;
    while(lo <= hi){
        int mid = (lo + hi)/2;
        if(escapable(mid)){
            ans = mid; lo = mid+1;
        }
        else{
            hi = mid-1;
        }
    }

    cout << ans << endl;
    return 0;
}

Compilation message

mecho.cpp: In function 'void bfs()':
mecho.cpp:34:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   34 |         auto[ux, uy] = qb.front(); qb.pop();
      |             ^
mecho.cpp: In function 'bool escapable(int)':
mecho.cpp:52:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   52 |         auto[x, y] = q.front(); q.pop();
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5332 KB Output is correct
2 Correct 3 ms 5332 KB Output is correct
3 Correct 4 ms 5332 KB Output is correct
4 Correct 3 ms 5332 KB Output is correct
5 Correct 4 ms 5332 KB Output is correct
6 Correct 4 ms 5332 KB Output is correct
7 Correct 63 ms 6136 KB Output is correct
8 Correct 3 ms 5332 KB Output is correct
9 Correct 3 ms 5332 KB Output is correct
10 Correct 3 ms 5332 KB Output is correct
11 Correct 4 ms 5408 KB Output is correct
12 Incorrect 3 ms 5332 KB Output isn't correct
13 Correct 3 ms 5332 KB Output is correct
14 Correct 3 ms 5332 KB Output is correct
15 Correct 3 ms 5332 KB Output is correct
16 Correct 3 ms 5332 KB Output is correct
17 Correct 3 ms 5332 KB Output is correct
18 Correct 3 ms 5332 KB Output is correct
19 Correct 3 ms 5332 KB Output is correct
20 Correct 3 ms 5332 KB Output is correct
21 Correct 5 ms 5332 KB Output is correct
22 Correct 4 ms 5432 KB Output is correct
23 Correct 3 ms 5332 KB Output is correct
24 Correct 3 ms 5332 KB Output is correct
25 Correct 3 ms 5332 KB Output is correct
26 Correct 3 ms 5332 KB Output is correct
27 Correct 3 ms 5332 KB Output is correct
28 Correct 4 ms 5448 KB Output is correct
29 Correct 3 ms 5332 KB Output is correct
30 Correct 3 ms 5460 KB Output is correct
31 Correct 3 ms 5460 KB Output is correct
32 Correct 3 ms 5460 KB Output is correct
33 Correct 5 ms 5588 KB Output is correct
34 Correct 5 ms 5588 KB Output is correct
35 Correct 19 ms 5676 KB Output is correct
36 Correct 7 ms 5708 KB Output is correct
37 Correct 6 ms 5712 KB Output is correct
38 Correct 23 ms 5716 KB Output is correct
39 Correct 7 ms 5632 KB Output is correct
40 Correct 7 ms 5716 KB Output is correct
41 Correct 26 ms 5716 KB Output is correct
42 Correct 7 ms 5700 KB Output is correct
43 Correct 7 ms 5676 KB Output is correct
44 Correct 31 ms 5700 KB Output is correct
45 Correct 8 ms 5808 KB Output is correct
46 Correct 8 ms 5832 KB Output is correct
47 Correct 38 ms 5716 KB Output is correct
48 Correct 13 ms 5876 KB Output is correct
49 Correct 10 ms 5844 KB Output is correct
50 Correct 50 ms 5784 KB Output is correct
51 Correct 10 ms 5844 KB Output is correct
52 Correct 12 ms 5844 KB Output is correct
53 Correct 64 ms 5912 KB Output is correct
54 Correct 11 ms 5852 KB Output is correct
55 Correct 11 ms 5952 KB Output is correct
56 Correct 66 ms 5944 KB Output is correct
57 Correct 12 ms 5972 KB Output is correct
58 Correct 15 ms 5872 KB Output is correct
59 Correct 110 ms 5980 KB Output is correct
60 Correct 16 ms 5972 KB Output is correct
61 Correct 17 ms 6004 KB Output is correct
62 Correct 84 ms 6012 KB Output is correct
63 Correct 85 ms 6012 KB Output is correct
64 Correct 127 ms 5972 KB Output is correct
65 Correct 140 ms 6012 KB Output is correct
66 Correct 124 ms 6012 KB Output is correct
67 Correct 88 ms 5944 KB Output is correct
68 Correct 37 ms 5972 KB Output is correct
69 Correct 35 ms 5956 KB Output is correct
70 Correct 34 ms 5960 KB Output is correct
71 Correct 30 ms 5968 KB Output is correct
72 Correct 25 ms 5984 KB Output is correct
73 Correct 30 ms 6228 KB Output is correct
74 Correct 46 ms 6296 KB Output is correct
75 Correct 53 ms 6288 KB Output is correct
76 Correct 55 ms 6316 KB Output is correct
77 Correct 49 ms 6288 KB Output is correct
78 Correct 63 ms 6260 KB Output is correct
79 Correct 52 ms 6168 KB Output is correct
80 Correct 46 ms 6260 KB Output is correct
81 Correct 52 ms 6228 KB Output is correct
82 Correct 46 ms 6220 KB Output is correct
83 Correct 56 ms 6220 KB Output is correct
84 Correct 60 ms 6228 KB Output is correct
85 Correct 56 ms 6148 KB Output is correct
86 Correct 59 ms 6228 KB Output is correct
87 Correct 70 ms 6224 KB Output is correct
88 Correct 56 ms 6096 KB Output is correct
89 Correct 57 ms 6172 KB Output is correct
90 Correct 64 ms 6092 KB Output is correct
91 Correct 61 ms 6096 KB Output is correct
92 Correct 57 ms 6100 KB Output is correct