답안 #953981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
953981 2024-03-27T03:45:18 Z Github Mecho (IOI09_mecho) C++17
46 / 100
125 ms 46076 KB
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <map>
#include <climits>
#include <cmath>
#include <algorithm>
#include <stack>
using namespace std;

#define speedup ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long

const ll MAXN = 810;
ll bee[MAXN][MAXN];
ll dist[MAXN][MAXN];
pair<ll,ll> parent[MAXN][MAXN];
bool vis[MAXN][MAXN];
ll dX[] = {1, -1, 0, 0};
ll dY[] = {0, 0, 1, -1};
pair<ll, ll> mencho, den;
vector<string> grid;
ll n, s;

bool compute(ll k){
    if (k >= bee[mencho.first][mencho.second]){
        return false;
    }
    for (ll i = 0; i < MAXN; i++){
        for (ll j = 0; j < MAXN; j++){
            dist[i][j] = 1e9;
            parent[i][j] = {-1, -1};
            vis[i][j] = false;
        }
    }
    queue<pair<ll, ll>> q;
    q.push(mencho);
    dist[mencho.first][mencho.second] = 0;
    while (!q.empty()){
        ll x = q.front().first, y = q.front().second; q.pop();
        vis[x][y] = true;
        if (make_pair(x, y) == den){
            break;
        }
        for (ll i = 0; i < 4; i++){
            ll nX = x + dX[i], nY = y+dY[i];
            bool b1 = nX < 0 || nX >= n || nY < 0 || nY >= n, b2 = grid[nX][nY] == 'T' || grid[nX][nY] == 'H' || grid[nX][nY] == 'D';
            if (b1 || b2){
                continue;
            }
            if (dist[nX][nY] > dist[x][y]+1 && !vis[nX][nY] && (bee[nX][nY]-k) > (dist[x][y]+1)/s){
                dist[nX][nY] = dist[x][y]+1;
                parent[nX][nY] = {x, y};
                q.push({nX, nY});
            }
        }
    }
    for (int i = 0; i < 4; i++){
        ll nX = den.first+dX[i], nY = den.second+dY[i];
        bool b1 = nX < 0 || nX >= n || nY < 0 || nY >= n, b2 = grid[nX][nY] == 'T' || grid[nX][nY] == 'H';
        if (b1 || b2) {
            continue;
        }
        if ((bee[nX][nY]-k) > (dist[nX][nY])/s){
            return true;
        }
    }
    return false;
}

int main() {
    speedup
    cin >> n >> s;
    grid.resize(n);
    vector<pair<ll, ll>> start;
    for (ll i = 0; i < n; i++){
        string st; cin >> st;
        grid[i] = st;
        for (ll j = 0; j < n; j++){
            if (st[j] == 'H'){
                start.push_back({i, j});
            }else if (st[j] == 'M'){
                mencho = {i, j};
            }else if (st[j] == 'D'){
                den = {i, j};
            }
        }
    }
    for (ll i = 0; i < MAXN; i++){
        for (ll j = 0; j < MAXN; j++){
            bee[i][j] = 1e9;
            vis[i][j] = false;
        }
    }
    queue<pair<ll, ll>> q;
    for (pair<ll, ll> p: start){
        bee[p.first][p.second] = 0;
        q.push({p.first, p.second});
    }
    while (!q.empty()){
        ll x = q.front().first, y = q.front().second; q.pop();
        vis[x][y] = true;
        for (ll i = 0; i < 4; i++){
            ll nX = x + dX[i], nY = y+dY[i];
            if (nX < 0 || nX >= n || nY < 0 || nY >= n || grid[nX][nY] == 'T' || grid[nX][nY] == 'D'){
                continue;
            }
            if (bee[nX][nY] > bee[x][y]+1 && !vis[nX][nY]){
                bee[nX][nY] = bee[x][y]+1;
                q.push({nX, nY});
            }
        }
    }
    ll l = 0, h = 1e9, mid, ans = -1;
    while (l <= h){
        mid = (l+h)/2;
        if (compute(mid)){
            ans = mid;
            l = mid+1;
        }else{
            h = mid-1;
        }
    }
    cout << ans << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21596 KB Output is correct
2 Correct 6 ms 21596 KB Output is correct
3 Correct 5 ms 21596 KB Output is correct
4 Correct 7 ms 21596 KB Output is correct
5 Runtime error 23 ms 43356 KB Execution killed with signal 11
6 Runtime error 21 ms 43352 KB Execution killed with signal 11
7 Correct 125 ms 22796 KB Output is correct
8 Runtime error 21 ms 43356 KB Execution killed with signal 11
9 Runtime error 21 ms 43372 KB Execution killed with signal 11
10 Runtime error 21 ms 43356 KB Execution killed with signal 11
11 Runtime error 21 ms 43352 KB Execution killed with signal 11
12 Correct 9 ms 21596 KB Output is correct
13 Correct 4 ms 21592 KB Output is correct
14 Correct 10 ms 21596 KB Output is correct
15 Correct 8 ms 21592 KB Output is correct
16 Runtime error 21 ms 43356 KB Execution killed with signal 11
17 Correct 9 ms 21596 KB Output is correct
18 Runtime error 22 ms 43384 KB Execution killed with signal 11
19 Correct 10 ms 21596 KB Output is correct
20 Runtime error 21 ms 43564 KB Execution killed with signal 11
21 Correct 10 ms 21596 KB Output is correct
22 Runtime error 21 ms 43356 KB Execution killed with signal 11
23 Correct 8 ms 21596 KB Output is correct
24 Runtime error 21 ms 43356 KB Execution killed with signal 11
25 Correct 11 ms 21596 KB Output is correct
26 Runtime error 21 ms 43356 KB Execution killed with signal 11
27 Correct 8 ms 21596 KB Output is correct
28 Runtime error 21 ms 43428 KB Execution killed with signal 11
29 Correct 10 ms 21596 KB Output is correct
30 Runtime error 22 ms 43384 KB Execution killed with signal 11
31 Correct 14 ms 21596 KB Output is correct
32 Runtime error 21 ms 43356 KB Execution killed with signal 11
33 Correct 17 ms 21596 KB Output is correct
34 Runtime error 22 ms 43788 KB Execution killed with signal 11
35 Runtime error 25 ms 43704 KB Execution killed with signal 11
36 Correct 16 ms 21904 KB Output is correct
37 Runtime error 24 ms 43868 KB Execution killed with signal 11
38 Runtime error 25 ms 43680 KB Execution killed with signal 11
39 Correct 16 ms 21880 KB Output is correct
40 Runtime error 24 ms 43824 KB Execution killed with signal 11
41 Runtime error 25 ms 43860 KB Execution killed with signal 11
42 Correct 12 ms 21852 KB Output is correct
43 Runtime error 31 ms 44112 KB Execution killed with signal 11
44 Runtime error 32 ms 44124 KB Execution killed with signal 11
45 Correct 20 ms 22104 KB Output is correct
46 Runtime error 25 ms 44124 KB Execution killed with signal 11
47 Runtime error 29 ms 44000 KB Execution killed with signal 11
48 Correct 21 ms 22052 KB Output is correct
49 Runtime error 26 ms 44376 KB Execution killed with signal 11
50 Runtime error 29 ms 44372 KB Execution killed with signal 11
51 Correct 22 ms 22360 KB Output is correct
52 Runtime error 31 ms 44380 KB Execution killed with signal 11
53 Runtime error 31 ms 44368 KB Execution killed with signal 11
54 Correct 27 ms 22108 KB Output is correct
55 Runtime error 29 ms 44636 KB Execution killed with signal 11
56 Runtime error 33 ms 44500 KB Execution killed with signal 11
57 Correct 21 ms 22108 KB Output is correct
58 Runtime error 28 ms 44636 KB Execution killed with signal 11
59 Runtime error 34 ms 44584 KB Execution killed with signal 11
60 Correct 23 ms 22108 KB Output is correct
61 Runtime error 28 ms 44820 KB Execution killed with signal 11
62 Runtime error 41 ms 44872 KB Execution killed with signal 11
63 Runtime error 38 ms 44880 KB Execution killed with signal 11
64 Runtime error 38 ms 44884 KB Execution killed with signal 11
65 Runtime error 40 ms 44884 KB Execution killed with signal 11
66 Runtime error 38 ms 44880 KB Execution killed with signal 11
67 Runtime error 37 ms 44880 KB Execution killed with signal 11
68 Runtime error 40 ms 44892 KB Execution killed with signal 11
69 Runtime error 39 ms 44892 KB Execution killed with signal 11
70 Runtime error 41 ms 44884 KB Execution killed with signal 11
71 Runtime error 40 ms 44888 KB Execution killed with signal 11
72 Runtime error 40 ms 44888 KB Execution killed with signal 11
73 Runtime error 45 ms 45964 KB Execution killed with signal 11
74 Runtime error 42 ms 46076 KB Execution killed with signal 11
75 Runtime error 42 ms 45956 KB Execution killed with signal 11
76 Runtime error 41 ms 45904 KB Execution killed with signal 11
77 Runtime error 42 ms 46004 KB Execution killed with signal 11
78 Correct 72 ms 22804 KB Output is correct
79 Correct 56 ms 22616 KB Output is correct
80 Correct 62 ms 22616 KB Output is correct
81 Correct 68 ms 22700 KB Output is correct
82 Correct 56 ms 22612 KB Output is correct
83 Correct 99 ms 22756 KB Output is correct
84 Correct 94 ms 22764 KB Output is correct
85 Correct 89 ms 22616 KB Output is correct
86 Correct 96 ms 22616 KB Output is correct
87 Correct 93 ms 22620 KB Output is correct
88 Correct 107 ms 22652 KB Output is correct
89 Correct 118 ms 22652 KB Output is correct
90 Correct 114 ms 22616 KB Output is correct
91 Correct 110 ms 22616 KB Output is correct
92 Correct 106 ms 22620 KB Output is correct