답안 #572136

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572136 2022-06-03T18:14:02 Z Vanilla Mecho (IOI09_mecho) C++17
100 / 100
309 ms 2520 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 810;
char a [maxn][maxn];
char c [maxn][maxn];
bool vis [maxn][maxn];
bool bad [maxn][maxn];
int n,s, sx, sy, ex, ey;
queue <pair <int, int> > startq;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

void propagate_bees(queue <pair <int, int> > &bee) {
    int k = bee.size();
    for (int i = 0; i < k; i++){
        int x = bee.front().first, y = bee.front().second;
        bee.pop();
        for (int j = 0; j < 4; j++){
            int nx = x + dx[j], ny = y + dy[j];
            if (nx < 0 || nx >= n || ny < 0 || ny >= n || 
                c[nx][ny] == 'T' || c[nx][ny] == 'D' || c[nx][ny] == 'H') continue;
            c[nx][ny] = 'H';
            bee.push({nx, ny});
        }
    }
}

bool check (int minutes) {
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            vis[i][j] = 0;
            c[i][j] = a[i][j];
        }
    }
    queue <pair <int, int> > bear, bee = startq;
    bear.push({sx, sy}); 
    // move bees for minutes before starting search
    while (minutes--) {
        propagate_bees(bee);
    }
    // for (int i = 0; i < n; i++){
    //     for (int j = 0; j < n; j++){
    //         cout << c[i][j];
    //     }
    //     cout << "\n";
    // }
    while (!bear.empty()){
        for (int z = 0; z < s; z++){
            int k = bear.size();
            for (int i = 0; i < k; i++){
                int x = bear.front().first, y = bear.front().second;
                bear.pop();
                if (c[x][y] == 'H') continue;
                for (int j = 0; j < 4; j++){
                    int nx = x + dx[j], ny = y + dy[j];
                    if (nx < 0 || nx >= n || ny < 0 || ny >= n || vis[nx][ny] || 
                        c[nx][ny] == 'T' || c[nx][ny] == 'H') continue;
                    if (c[nx][ny] == 'D') return 1;
                    vis[nx][ny] = 1;
                    bear.push({nx, ny});
                }
            }
        }
        int k = bee.size();
        propagate_bees(bee);
    }
    return 0;

}

int main() {
    cin >> n >> s;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        for (int j = 0; j < n; j++){
            if (a[i][j] == 'M') {
                sx = i, sy = j;
                a[i][j] = 'G';
            }
            if (a[i][j] == 'D') {
                ex = i, ey = j;
            }
            if (a[i][j] == 'H') {
                startq.push({i,j});
            }
        }
    }
    // cout << check(1);
    int l = 0, r = maxn * maxn, rs = -1;
    while (l <= r) {
        int mid = (l + r) / 2;
        if (check(mid)) {
            rs = mid;
            l = mid + 1;
        }
        else {
            r = mid - 1;
        }
    }
    cout << rs;
    return 0;
}

Compilation message

mecho.cpp: In function 'bool check(int)':
mecho.cpp:65:13: warning: unused variable 'k' [-Wunused-variable]
   65 |         int k = bee.size();
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 212 KB Output is correct
2 Correct 4 ms 212 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 3 ms 340 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 251 ms 2324 KB Output is correct
8 Correct 4 ms 340 KB Output is correct
9 Correct 4 ms 340 KB Output is correct
10 Correct 5 ms 340 KB Output is correct
11 Correct 5 ms 340 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 340 KB Output is correct
14 Correct 5 ms 468 KB Output is correct
15 Correct 4 ms 340 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 4 ms 340 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 4 ms 396 KB Output is correct
20 Correct 4 ms 340 KB Output is correct
21 Correct 4 ms 424 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
23 Correct 4 ms 340 KB Output is correct
24 Correct 6 ms 340 KB Output is correct
25 Correct 4 ms 468 KB Output is correct
26 Correct 5 ms 468 KB Output is correct
27 Correct 5 ms 468 KB Output is correct
28 Correct 6 ms 468 KB Output is correct
29 Correct 4 ms 468 KB Output is correct
30 Correct 4 ms 468 KB Output is correct
31 Correct 5 ms 468 KB Output is correct
32 Correct 5 ms 468 KB Output is correct
33 Correct 30 ms 1108 KB Output is correct
34 Correct 28 ms 1152 KB Output is correct
35 Correct 40 ms 1108 KB Output is correct
36 Correct 38 ms 1236 KB Output is correct
37 Correct 38 ms 1256 KB Output is correct
38 Correct 49 ms 1252 KB Output is correct
39 Correct 50 ms 1368 KB Output is correct
40 Correct 43 ms 1372 KB Output is correct
41 Correct 60 ms 1392 KB Output is correct
42 Correct 61 ms 1612 KB Output is correct
43 Correct 53 ms 1492 KB Output is correct
44 Correct 82 ms 1496 KB Output is correct
45 Correct 72 ms 1612 KB Output is correct
46 Correct 64 ms 1624 KB Output is correct
47 Correct 87 ms 1620 KB Output is correct
48 Correct 87 ms 1748 KB Output is correct
49 Correct 96 ms 1728 KB Output is correct
50 Correct 103 ms 1748 KB Output is correct
51 Correct 93 ms 1844 KB Output is correct
52 Correct 87 ms 1868 KB Output is correct
53 Correct 132 ms 1856 KB Output is correct
54 Correct 104 ms 1960 KB Output is correct
55 Correct 95 ms 1876 KB Output is correct
56 Correct 146 ms 1972 KB Output is correct
57 Correct 142 ms 2152 KB Output is correct
58 Correct 115 ms 2088 KB Output is correct
59 Correct 169 ms 2004 KB Output is correct
60 Correct 138 ms 2208 KB Output is correct
61 Correct 136 ms 2104 KB Output is correct
62 Correct 179 ms 2208 KB Output is correct
63 Correct 265 ms 2204 KB Output is correct
64 Correct 279 ms 2208 KB Output is correct
65 Correct 257 ms 2220 KB Output is correct
66 Correct 260 ms 2216 KB Output is correct
67 Correct 278 ms 2252 KB Output is correct
68 Correct 261 ms 2132 KB Output is correct
69 Correct 241 ms 2244 KB Output is correct
70 Correct 287 ms 2236 KB Output is correct
71 Correct 263 ms 2240 KB Output is correct
72 Correct 291 ms 2240 KB Output is correct
73 Correct 226 ms 2508 KB Output is correct
74 Correct 257 ms 2504 KB Output is correct
75 Correct 278 ms 2508 KB Output is correct
76 Correct 286 ms 2448 KB Output is correct
77 Correct 271 ms 2520 KB Output is correct
78 Correct 292 ms 2388 KB Output is correct
79 Correct 254 ms 2468 KB Output is correct
80 Correct 270 ms 2480 KB Output is correct
81 Correct 269 ms 2516 KB Output is correct
82 Correct 266 ms 2392 KB Output is correct
83 Correct 290 ms 2492 KB Output is correct
84 Correct 260 ms 2424 KB Output is correct
85 Correct 275 ms 2508 KB Output is correct
86 Correct 277 ms 2424 KB Output is correct
87 Correct 309 ms 2444 KB Output is correct
88 Correct 259 ms 2520 KB Output is correct
89 Correct 262 ms 2388 KB Output is correct
90 Correct 294 ms 2380 KB Output is correct
91 Correct 264 ms 2388 KB Output is correct
92 Correct 264 ms 2376 KB Output is correct