답안 #1101372

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101372 2024-10-16T07:29:43 Z jadai007 Mecho (IOI09_mecho) C++17
23 / 100
134 ms 9236 KB
#include<bits/stdc++.h>

using namespace std;

int n, s, disH[1010][1010], dis[1010][1010], xx[] = {0, 0, -1, 1}, xy[] = {-1, 1, 0, 0};
char mp[1010][1010];
queue<tuple<int, int, int>> q;

bool solve(int mid){
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            if(mp[i][j] == 'M') q.emplace(i, j, 0), dis[i][j] = 0;
            else dis[i][j] = 1e9;
        }
    }
    while(!q.empty()){
        int x = get<0>(q.front()), y = get<1>(q.front()), w = get<2>(q.front()); q.pop();
        if(dis[x][y] < w || (dis[x][y] + 1) / s >= disH[x][y] - mid) continue;
        if(mp[x][y] == 'D') return true;
        for(int i = 0; i < 4; ++i){
            int nx = x + xx[i];
            int ny = y + xy[i];
            if(nx < 1 || nx > n || ny < 1 || ny > n || mp[nx][ny] == 'T') continue;
            if(dis[nx][ny] > w + 1){
                dis[nx][ny] = w + 1;
                q.emplace(nx, ny, w + 1);
            }
        }
    }
    return false;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> s;
    for(int i = 1; i<=n; ++i) for(int j = 1; j <= n; ++j) cin >> mp[i][j];
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <=n; ++j){
            if(mp[i][j] == 'H') q.emplace(i, j, 0), disH[i][j] = 0;
            else disH[i][j] = 1e9;
        }
    }
    while(!q.empty()){
        int x = get<0>(q.front()), y = get<1>(q.front()), w = get<2>(q.front()); q.pop();
        if(disH[x][y] < w) continue;
        for(int i = 0; i < 4; ++i){
            int nx = x + xx[i];
            int ny = y + xy[i];
            if(nx < 1 || nx > n || ny < 1 || ny > n || mp[nx][ny] == 'T') continue;
            if(disH[nx][ny] > w + 1){
                disH[nx][ny] = w + 1;
                q.emplace(nx, ny, w + 1);
            }
        }   
    }
    int l = 0, r = 1e9, ans = -1;
    while(l <= r){
        int mid = (l + r) >> 1;
        if(solve(mid)) ans = mid, l = mid + 1;
        else r = mid - 1;
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4432 KB Output isn't correct
2 Incorrect 1 ms 4600 KB Output isn't correct
3 Incorrect 1 ms 4432 KB Output isn't correct
4 Incorrect 1 ms 4432 KB Output isn't correct
5 Correct 1 ms 4684 KB Output is correct
6 Incorrect 1 ms 4432 KB Output isn't correct
7 Incorrect 67 ms 8784 KB Output isn't correct
8 Correct 1 ms 4432 KB Output is correct
9 Incorrect 1 ms 4432 KB Output isn't correct
10 Incorrect 1 ms 4432 KB Output isn't correct
11 Correct 1 ms 4432 KB Output is correct
12 Incorrect 1 ms 4432 KB Output isn't correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Incorrect 1 ms 4432 KB Output isn't correct
16 Correct 1 ms 4432 KB Output is correct
17 Incorrect 1 ms 4432 KB Output isn't correct
18 Correct 1 ms 4432 KB Output is correct
19 Incorrect 1 ms 4432 KB Output isn't correct
20 Correct 1 ms 4600 KB Output is correct
21 Incorrect 1 ms 4432 KB Output isn't correct
22 Correct 1 ms 4432 KB Output is correct
23 Incorrect 1 ms 4432 KB Output isn't correct
24 Correct 1 ms 4640 KB Output is correct
25 Incorrect 1 ms 4432 KB Output isn't correct
26 Correct 2 ms 4616 KB Output is correct
27 Incorrect 2 ms 4432 KB Output isn't correct
28 Correct 2 ms 4432 KB Output is correct
29 Incorrect 1 ms 4432 KB Output isn't correct
30 Correct 1 ms 4432 KB Output is correct
31 Incorrect 1 ms 4604 KB Output isn't correct
32 Correct 2 ms 4432 KB Output is correct
33 Incorrect 6 ms 8848 KB Output isn't correct
34 Correct 7 ms 8784 KB Output is correct
35 Correct 16 ms 8784 KB Output is correct
36 Incorrect 8 ms 8784 KB Output isn't correct
37 Correct 9 ms 8784 KB Output is correct
38 Correct 20 ms 8784 KB Output is correct
39 Incorrect 10 ms 8856 KB Output isn't correct
40 Correct 10 ms 8784 KB Output is correct
41 Correct 30 ms 8860 KB Output is correct
42 Incorrect 12 ms 8784 KB Output isn't correct
43 Correct 12 ms 8956 KB Output is correct
44 Correct 34 ms 8784 KB Output is correct
45 Incorrect 13 ms 8784 KB Output isn't correct
46 Correct 13 ms 8784 KB Output is correct
47 Correct 40 ms 8784 KB Output is correct
48 Incorrect 16 ms 9016 KB Output isn't correct
49 Correct 16 ms 8852 KB Output is correct
50 Correct 48 ms 8952 KB Output is correct
51 Incorrect 18 ms 8840 KB Output isn't correct
52 Correct 21 ms 8784 KB Output is correct
53 Correct 54 ms 8784 KB Output is correct
54 Incorrect 21 ms 8784 KB Output isn't correct
55 Correct 21 ms 8784 KB Output is correct
56 Correct 63 ms 8784 KB Output is correct
57 Incorrect 25 ms 8784 KB Output isn't correct
58 Correct 24 ms 8784 KB Output is correct
59 Correct 73 ms 8784 KB Output is correct
60 Incorrect 27 ms 8784 KB Output isn't correct
61 Correct 27 ms 8784 KB Output is correct
62 Correct 85 ms 8784 KB Output is correct
63 Incorrect 76 ms 8784 KB Output isn't correct
64 Incorrect 134 ms 8784 KB Output isn't correct
65 Correct 132 ms 8784 KB Output is correct
66 Correct 101 ms 8784 KB Output is correct
67 Correct 90 ms 8588 KB Output is correct
68 Correct 49 ms 8784 KB Output is correct
69 Incorrect 48 ms 9076 KB Output isn't correct
70 Correct 38 ms 8784 KB Output is correct
71 Correct 40 ms 8844 KB Output is correct
72 Correct 37 ms 8636 KB Output is correct
73 Correct 49 ms 9040 KB Output is correct
74 Incorrect 54 ms 9040 KB Output isn't correct
75 Correct 57 ms 9040 KB Output is correct
76 Incorrect 53 ms 9164 KB Output isn't correct
77 Correct 61 ms 9040 KB Output is correct
78 Correct 62 ms 9040 KB Output is correct
79 Correct 50 ms 9040 KB Output is correct
80 Correct 54 ms 9236 KB Output is correct
81 Correct 59 ms 9040 KB Output is correct
82 Correct 51 ms 9040 KB Output is correct
83 Correct 64 ms 9040 KB Output is correct
84 Incorrect 61 ms 9052 KB Output isn't correct
85 Correct 60 ms 9152 KB Output is correct
86 Correct 74 ms 9040 KB Output is correct
87 Correct 69 ms 9040 KB Output is correct
88 Correct 65 ms 9040 KB Output is correct
89 Incorrect 73 ms 9040 KB Output isn't correct
90 Correct 68 ms 9040 KB Output is correct
91 Correct 65 ms 9040 KB Output is correct
92 Correct 65 ms 9040 KB Output is correct