답안 #581547

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581547 2022-06-22T17:47:36 Z Saeed_247 Mecho (IOI09_mecho) C++17
38 / 100
728 ms 11864 KB
#include <bits/stdc++.h>
using namespace std;
template<typename T> void dout(string name, T arg) {
    cerr << name << " = " << arg << "\e[39m" << endl;
}
template<typename T1, typename... T2> void dout(string names, T1 arg, T2... args) {
    cerr << names.substr(0, names.find(',')) << " = " << arg << " | ";
    dout(names.substr(names.find(',') + 2), args...);
}
#define debug(...) cerr << "\e[91m" << "[" << __LINE__ << ":" << __func__ << "]=> ", dout(#__VA_ARGS__,  __VA_ARGS__);

const pair<int, int> dir[] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
const int N = 800;
bool visited[N][N];
long long n, s;
vector<vector<char>> arr;
vector<pair<long long, long long>> hives;
pair<long long, long long> m, d;
queue<pair<long long, long long>> q;

bool move(int x, int y) {
    return x >= 0 && y >= 0 && x < n && y < n;
}

inline long long get_tim(long long x) {
    return x / s + (x % s != 0);
}

bool check(long long tim, vector<vector<long long>>& swarm) {
    vector<vector<long long>> dist(n, vector<long long>(n, 1e18));
    dist[m.first][m.second] = 0;
    q.push(m);
    while (!q.empty()) {
        auto [x, y] = q.front();
        q.pop();
        for (auto [xx, yy] : dir) if (move(x + xx, y + yy) && (arr[x + xx][y + yy] == 'G' || arr[x + xx][y + yy] == 'D')
             && dist[x + xx][y + yy] > dist[x][y] + 1 && get_tim(dist[x][y] + 1) + tim <= swarm[x + xx][y + yy]) {
                dist[x + xx][y + yy] = dist[x][y] + 1;
                q.push({x + xx, y + yy});
        }
    }
    return dist[d.first][d.second] < 1e18;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> s;
    arr.resize(n, vector<char> (n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> arr[i][j];
            if (arr[i][j] == 'M') {
                m = {i, j};
            }
            if (arr[i][j] == 'H') {
                hives.push_back({i, j});
            }
            if (arr[i][j] == 'D') {
                d = {i, j};
            }
        }
    }

    vector<vector<long long>> swarm(n, vector<long long>(n, 1e18));
    for (auto [x, y] : hives) {
        swarm[x][y] = 0;
        q.push({x, y});
    }
    while (!q.empty()) {
        auto [x, y] = q.front();
        q.pop();
        for (auto [xx, yy] : dir) if (move(x + xx, y + yy) && (arr[x + xx][y + yy] == 'G' || arr[x + xx][y + yy] == 'M')
             && swarm[x + xx][y + yy] > swarm[x][y] + 1) {
                swarm[x + xx][y + yy] = swarm[x][y] + 1;
                q.push({x + xx, y + yy});
        }
    }

    long long l = -1e9, h = 1e9;
    while (h - l > 1) {
        long long mid = (h + l) / 2;
        if (check(mid, swarm)) l = mid;
        else h = mid;
    }
    if (l < 0)
        cout << -1 << '\n';
    else 
        cout << l << '\n';
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Incorrect 1 ms 212 KB Output isn't correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 164 ms 11724 KB Output is correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Incorrect 1 ms 344 KB Output isn't correct
13 Incorrect 1 ms 344 KB Output isn't correct
14 Correct 3 ms 332 KB Output is correct
15 Incorrect 1 ms 340 KB Output isn't correct
16 Correct 1 ms 212 KB Output is correct
17 Incorrect 1 ms 340 KB Output isn't correct
18 Correct 1 ms 340 KB Output is correct
19 Incorrect 1 ms 336 KB Output isn't correct
20 Correct 1 ms 340 KB Output is correct
21 Incorrect 1 ms 340 KB Output isn't correct
22 Correct 1 ms 324 KB Output is correct
23 Incorrect 1 ms 344 KB Output isn't correct
24 Correct 1 ms 332 KB Output is correct
25 Incorrect 1 ms 340 KB Output isn't correct
26 Correct 1 ms 340 KB Output is correct
27 Incorrect 1 ms 340 KB Output isn't correct
28 Correct 1 ms 340 KB Output is correct
29 Incorrect 1 ms 340 KB Output isn't correct
30 Correct 1 ms 340 KB Output is correct
31 Incorrect 1 ms 340 KB Output isn't correct
32 Correct 1 ms 340 KB Output is correct
33 Incorrect 14 ms 2640 KB Output isn't correct
34 Correct 14 ms 2528 KB Output is correct
35 Correct 31 ms 2524 KB Output is correct
36 Incorrect 17 ms 3256 KB Output isn't correct
37 Correct 18 ms 3296 KB Output is correct
38 Correct 49 ms 3256 KB Output is correct
39 Incorrect 22 ms 4004 KB Output isn't correct
40 Correct 23 ms 3924 KB Output is correct
41 Correct 58 ms 4004 KB Output is correct
42 Incorrect 32 ms 4888 KB Output isn't correct
43 Correct 31 ms 4792 KB Output is correct
44 Correct 84 ms 4900 KB Output is correct
45 Incorrect 36 ms 5916 KB Output isn't correct
46 Correct 34 ms 5784 KB Output is correct
47 Correct 96 ms 5792 KB Output is correct
48 Incorrect 40 ms 6812 KB Output isn't correct
49 Correct 46 ms 6768 KB Output is correct
50 Correct 115 ms 6872 KB Output is correct
51 Incorrect 48 ms 7924 KB Output isn't correct
52 Correct 53 ms 8000 KB Output is correct
53 Correct 150 ms 7916 KB Output is correct
54 Incorrect 60 ms 9236 KB Output isn't correct
55 Correct 64 ms 9136 KB Output is correct
56 Correct 172 ms 9104 KB Output is correct
57 Incorrect 64 ms 10404 KB Output isn't correct
58 Correct 72 ms 10380 KB Output is correct
59 Correct 202 ms 10392 KB Output is correct
60 Incorrect 88 ms 11756 KB Output isn't correct
61 Correct 86 ms 11656 KB Output is correct
62 Correct 253 ms 11680 KB Output is correct
63 Correct 193 ms 11664 KB Output is correct
64 Correct 318 ms 11640 KB Output is correct
65 Correct 313 ms 11856 KB Output is correct
66 Incorrect 241 ms 11744 KB Output isn't correct
67 Correct 728 ms 11684 KB Output is correct
68 Correct 117 ms 11752 KB Output is correct
69 Correct 171 ms 11776 KB Output is correct
70 Correct 129 ms 11804 KB Output is correct
71 Correct 98 ms 11788 KB Output is correct
72 Incorrect 140 ms 11692 KB Output isn't correct
73 Incorrect 117 ms 11776 KB Output isn't correct
74 Correct 158 ms 11732 KB Output is correct
75 Correct 156 ms 11756 KB Output is correct
76 Correct 140 ms 11784 KB Output is correct
77 Correct 151 ms 11744 KB Output is correct
78 Correct 647 ms 11664 KB Output is correct
79 Correct 141 ms 11784 KB Output is correct
80 Correct 128 ms 11828 KB Output is correct
81 Correct 131 ms 11720 KB Output is correct
82 Correct 125 ms 11744 KB Output is correct
83 Correct 161 ms 11828 KB Output is correct
84 Correct 166 ms 11732 KB Output is correct
85 Correct 141 ms 11764 KB Output is correct
86 Correct 155 ms 11788 KB Output is correct
87 Correct 155 ms 11732 KB Output is correct
88 Correct 155 ms 11816 KB Output is correct
89 Correct 207 ms 11864 KB Output is correct
90 Correct 182 ms 11748 KB Output is correct
91 Correct 171 ms 11688 KB Output is correct
92 Correct 183 ms 11784 KB Output is correct