답안 #1073887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1073887 2024-08-25T01:54:29 Z gavangno01 Mecho (IOI09_mecho) C++17
38 / 100
164 ms 9004 KB
#include<bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;

const int dx[] = {1, 0, 0, -1};
const int dy[] = {0, 1, -1, 0};
const int MAXN = 8e2 + 10;
const int inf = 1e9 + 7;
int n, s;
int xe, ye;
int grid[MAXN][MAXN];
int loangbee[MAXN][MAXN];
int loangpl[MAXN][MAXN];

bool exceed(int x, int y) {
    return (x > n || x < 1 || y > n || y < 1);
}
void bfsbee() {
    queue<pair<int, int>> q;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (grid[i][j] == 4) {
                q.push({i, j});
                loangbee[i][j] = 0;
            }
        }
    }
    while (!q.empty()) {
        pii temp = q.front();
        q.pop();
        int x = temp.fi;
        int y = temp.se;
        for (int i = 0; i < 4; i++) {
            int u = x + dx[i];
            int v = y + dy[i];
            if (!exceed(u, v)) {
                if (loangbee[u][v] == inf && grid[u][v] == 1) {
                    loangbee[u][v] = loangbee[x][y] + 1;
                    q.push({u, v});
                }
            }
        }
    }
}
int bfspl(int original_value) {
    queue<pair<int, int>> q;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (grid[i][j] == 2) {
                q.push({i, j});
                loangpl[i][j] = 0;
            }
            else {
                loangpl[i][j] = inf;
            }
        }
    }
    while (!q.empty()) {
        pii temp = q.front();
        q.pop();
        int x = temp.fi;
        int y = temp.se;
        int time = loangpl[x][y] / s;
        if (loangpl[x][y] % s != 0) time++;
        time += original_value;
        if (time > loangbee[x][y]) {
            loangpl[x][y] = -1;
            continue;
        }
        for (int i = 0; i < 4; i++) {
            int u = x + dx[i];
            int v = y + dy[i];
            if (!exceed(u, v)) {
                if (loangpl[u][v] == inf && grid[u][v] == 1) {
                    q.push({u, v});
                    loangpl[u][v] = loangpl[x][y] + 1;
                }
            }
        }
    }
    int timedi = loangpl[xe][ye] / s;
    if (loangpl[xe][ye] % s != 0) timedi++;
    if (timedi + original_value > loangbee[xe][ye]) return -1;
    else return 1;
}

int main() {
    cin >> n >> s;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            loangpl[i][j] = inf;
            loangbee[i][j] = inf;
            char c;
            cin >> c;
            if (c == 'T') {
                grid[i][j] = 0;
            }
            if (c == 'G') grid[i][j] = 1;
            if (c == 'M') grid[i][j] = 2;
            if (c == 'D') {
                grid[i][j] = 1;
                xe = i;
                ye = j;
            }
            if (c == 'H') grid[i][j] = 4;
        }
    }
    bfsbee();
//    for (int i = 1; i <= n; i++) {
//        for (int j = 1; j <= n; j++) {
//            cout << loangbee[i][j] << " ";
//        }
//        cout << endl;
//    }
//    cout << "map nguoi" << endl;
//    for (int i = 1; i <= n; i++) {
//        for (int j = 1; j <= n; j++) {
//            cout << loangpl[i][j] << " ";
//        }
//        cout << endl;
//
    int l = 0, r = n * n;
    while (l <= r) {

        int mid = (l + r) / 2;
        if (bfspl(mid) == 1) {
            l = mid + 1;
        }
        else r = mid - 1;
    }
    cout << l - 1;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 448 KB Output isn't correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Incorrect 1 ms 4444 KB Output isn't correct
4 Incorrect 1 ms 4444 KB Output isn't correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 77 ms 8668 KB Output is correct
8 Incorrect 1 ms 4444 KB Output isn't correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Incorrect 2 ms 6748 KB Output isn't correct
13 Incorrect 1 ms 4700 KB Output isn't correct
14 Correct 1 ms 6748 KB Output is correct
15 Incorrect 1 ms 4444 KB Output isn't correct
16 Correct 1 ms 4552 KB Output is correct
17 Incorrect 1 ms 4444 KB Output isn't correct
18 Correct 1 ms 2652 KB Output is correct
19 Incorrect 1 ms 4444 KB Output isn't correct
20 Correct 1 ms 604 KB Output is correct
21 Incorrect 1 ms 4444 KB Output isn't correct
22 Correct 1 ms 4444 KB Output is correct
23 Incorrect 1 ms 856 KB Output isn't correct
24 Correct 1 ms 4556 KB Output is correct
25 Incorrect 1 ms 6748 KB Output isn't correct
26 Correct 1 ms 6748 KB Output is correct
27 Incorrect 2 ms 6748 KB Output isn't correct
28 Correct 2 ms 4700 KB Output is correct
29 Incorrect 1 ms 2908 KB Output isn't correct
30 Correct 1 ms 4700 KB Output is correct
31 Incorrect 1 ms 4800 KB Output isn't correct
32 Correct 2 ms 1116 KB Output is correct
33 Incorrect 12 ms 4636 KB Output isn't correct
34 Correct 8 ms 6748 KB Output is correct
35 Correct 19 ms 6748 KB Output is correct
36 Incorrect 10 ms 7000 KB Output isn't correct
37 Correct 11 ms 7004 KB Output is correct
38 Correct 22 ms 6852 KB Output is correct
39 Incorrect 13 ms 7004 KB Output isn't correct
40 Correct 15 ms 7004 KB Output is correct
41 Correct 34 ms 4696 KB Output is correct
42 Incorrect 17 ms 7260 KB Output isn't correct
43 Correct 16 ms 7256 KB Output is correct
44 Correct 40 ms 7260 KB Output is correct
45 Incorrect 18 ms 7612 KB Output isn't correct
46 Correct 20 ms 7516 KB Output is correct
47 Correct 44 ms 7600 KB Output is correct
48 Incorrect 24 ms 6720 KB Output isn't correct
49 Correct 23 ms 6748 KB Output is correct
50 Correct 58 ms 6748 KB Output is correct
51 Incorrect 25 ms 7772 KB Output isn't correct
52 Correct 28 ms 6812 KB Output is correct
53 Correct 68 ms 7872 KB Output is correct
54 Incorrect 35 ms 7768 KB Output isn't correct
55 Correct 32 ms 7516 KB Output is correct
56 Correct 74 ms 8028 KB Output is correct
57 Incorrect 32 ms 8128 KB Output isn't correct
58 Correct 47 ms 8120 KB Output is correct
59 Correct 97 ms 7940 KB Output is correct
60 Incorrect 36 ms 8536 KB Output isn't correct
61 Correct 36 ms 8540 KB Output is correct
62 Correct 133 ms 8668 KB Output is correct
63 Correct 93 ms 8724 KB Output is correct
64 Correct 164 ms 8428 KB Output is correct
65 Correct 147 ms 8664 KB Output is correct
66 Incorrect 132 ms 8452 KB Output isn't correct
67 Correct 105 ms 8540 KB Output is correct
68 Correct 67 ms 8748 KB Output is correct
69 Correct 67 ms 8540 KB Output is correct
70 Correct 53 ms 8532 KB Output is correct
71 Correct 71 ms 8532 KB Output is correct
72 Incorrect 49 ms 8536 KB Output isn't correct
73 Incorrect 85 ms 8788 KB Output isn't correct
74 Correct 60 ms 9004 KB Output is correct
75 Correct 70 ms 8992 KB Output is correct
76 Correct 66 ms 9004 KB Output is correct
77 Correct 59 ms 8996 KB Output is correct
78 Correct 67 ms 8796 KB Output is correct
79 Correct 82 ms 8968 KB Output is correct
80 Correct 58 ms 8792 KB Output is correct
81 Correct 64 ms 8820 KB Output is correct
82 Correct 65 ms 8880 KB Output is correct
83 Correct 70 ms 8824 KB Output is correct
84 Correct 66 ms 8784 KB Output is correct
85 Correct 68 ms 8784 KB Output is correct
86 Correct 67 ms 8928 KB Output is correct
87 Correct 66 ms 8788 KB Output is correct
88 Correct 70 ms 8788 KB Output is correct
89 Correct 69 ms 8788 KB Output is correct
90 Correct 72 ms 8792 KB Output is correct
91 Correct 71 ms 8792 KB Output is correct
92 Correct 74 ms 8796 KB Output is correct