답안 #773343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
773343 2023-07-04T23:19:59 Z sz1218 Mecho (IOI09_mecho) C++14
84 / 100
134 ms 6924 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(queue<pi> &q, int dis[][NN]){
    while(!q.empty()){
        auto[ux, uy] = q.front(); q.pop();
        For(d, 0, 4){
            int nx = ux + dir[d][0],  ny = uy + dir[d][1];
            if(check(nx, ny)){
                if(dis[nx][ny] == INF){
                    dis[nx][ny] = dis[ux][uy] + 1;
                    q.push({nx, ny});
                }
            }
        }
    }
}

bool escapable(int delay){
    memset(dism, 0x3f, sizeof(dism));
    queue<pi> q; q.push({mx, my});dism[mx][my] = 0;
    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(dism, 0x3f, sizeof(0x3f)); 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;
                dism[i][j] = 0;
            }
            if(g[i][j] == 'H'){
                qb.push({i, j}); disb[i][j] = 0;
            }
            if(g[i][j] == 'D'){
                ex = i; ey = j;
            }
        }
    }

    bfs(qb, disb); 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(std::queue<std::pair<int, int> >&, int (*)[805])':
mecho.cpp:34:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   34 |         auto[ux, uy] = q.front(); q.pop();
      |             ^
mecho.cpp: In function 'bool escapable(int)':
mecho.cpp:51:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |         auto[x, y] = q.front(); q.pop();
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5332 KB Output is correct
2 Correct 4 ms 5332 KB Output is correct
3 Correct 3 ms 5324 KB Output is correct
4 Correct 3 ms 5332 KB Output is correct
5 Correct 3 ms 5332 KB Output is correct
6 Correct 3 ms 5332 KB Output is correct
7 Correct 63 ms 6664 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 5320 KB Output is correct
11 Correct 3 ms 5332 KB Output is correct
12 Incorrect 3 ms 5332 KB Output isn't correct
13 Incorrect 3 ms 5332 KB Output isn't correct
14 Correct 3 ms 5460 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 3 ms 5332 KB Output is correct
22 Correct 3 ms 5332 KB Output is correct
23 Correct 3 ms 5332 KB Output is correct
24 Correct 3 ms 5448 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 3 ms 5448 KB Output is correct
29 Correct 3 ms 5460 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 5716 KB Output is correct
34 Correct 5 ms 5716 KB Output is correct
35 Correct 16 ms 5800 KB Output is correct
36 Correct 6 ms 5840 KB Output is correct
37 Correct 6 ms 5840 KB Output is correct
38 Correct 21 ms 5844 KB Output is correct
39 Correct 6 ms 5844 KB Output is correct
40 Correct 6 ms 5832 KB Output is correct
41 Correct 25 ms 5844 KB Output is correct
42 Correct 7 ms 5940 KB Output is correct
43 Correct 7 ms 5956 KB Output is correct
44 Correct 31 ms 6028 KB Output is correct
45 Correct 8 ms 6120 KB Output is correct
46 Correct 8 ms 6068 KB Output is correct
47 Correct 38 ms 6100 KB Output is correct
48 Correct 9 ms 6228 KB Output is correct
49 Correct 9 ms 6112 KB Output is correct
50 Correct 45 ms 6224 KB Output is correct
51 Correct 10 ms 6332 KB Output is correct
52 Correct 10 ms 6228 KB Output is correct
53 Correct 51 ms 6316 KB Output is correct
54 Correct 11 ms 6356 KB Output is correct
55 Correct 11 ms 6344 KB Output is correct
56 Correct 66 ms 6420 KB Output is correct
57 Correct 12 ms 6484 KB Output is correct
58 Correct 12 ms 6484 KB Output is correct
59 Correct 73 ms 6452 KB Output is correct
60 Correct 14 ms 6544 KB Output is correct
61 Correct 14 ms 6616 KB Output is correct
62 Correct 82 ms 6644 KB Output is correct
63 Correct 79 ms 6644 KB Output is correct
64 Correct 134 ms 6640 KB Output is correct
65 Correct 127 ms 6564 KB Output is correct
66 Correct 105 ms 6548 KB Output is correct
67 Correct 91 ms 6644 KB Output is correct
68 Correct 41 ms 6668 KB Output is correct
69 Correct 33 ms 6592 KB Output is correct
70 Correct 33 ms 6608 KB Output is correct
71 Correct 33 ms 6548 KB Output is correct
72 Incorrect 27 ms 6592 KB Output isn't correct
73 Incorrect 30 ms 6844 KB Output isn't correct
74 Correct 45 ms 6924 KB Output is correct
75 Correct 48 ms 6920 KB Output is correct
76 Correct 44 ms 6860 KB Output is correct
77 Correct 48 ms 6836 KB Output is correct
78 Correct 53 ms 6900 KB Output is correct
79 Correct 43 ms 6820 KB Output is correct
80 Correct 46 ms 6896 KB Output is correct
81 Correct 52 ms 6900 KB Output is correct
82 Correct 48 ms 6820 KB Output is correct
83 Correct 56 ms 6868 KB Output is correct
84 Correct 49 ms 6868 KB Output is correct
85 Correct 51 ms 6848 KB Output is correct
86 Correct 58 ms 6836 KB Output is correct
87 Correct 59 ms 6868 KB Output is correct
88 Correct 62 ms 6740 KB Output is correct
89 Correct 56 ms 6804 KB Output is correct
90 Correct 66 ms 6732 KB Output is correct
91 Correct 59 ms 6804 KB Output is correct
92 Correct 57 ms 6812 KB Output is correct