답안 #789661

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789661 2023-07-21T16:31:29 Z phongcd Mecho (IOI09_mecho) C++17
27 / 100
277 ms 65540 KB
#include <bits/stdc++.h>
#define ll long long
#define ld long  double
#define ull unsigned long long
#define ii pair <int, int>
#define ill pair <ll, ll>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define file "test"
using namespace std;
const ll N = 8e2 + 2;
const ll MOD = 1e9;
const ll INF = 1e18;
const ll base = 311;
const int BLOCK_SIZE = 2000;
 
int n, s;
ii start, target, d[N][N];
char a[N][N];
int mtime[N][N];
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};
 
void addstep(ii &a) {
    a.se += 1;
    if (a.se == s) a.fi ++, a.se = 0;
}
 
bool cmp(ii a, ii b) {
    if (a.fi != b.fi) return a.fi < b.fi;
    return a.se < b.se; 
}
 
bool check(int x) {
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= n; j ++) d[i][j] = {2e9, 0};
    
    queue <ii> h;
    h.push(start);
    d[start.fi][start.se] = {x + 1, 0};
 
    while (!h.empty()) {
        auto [x, y] = h.front(); h.pop();
        ii res = d[x][y];
        addstep(res);
 
        for (int j = 0; j <= 3; j ++) {
            int u = x + dx[j];
            int v = y + dy[j];
            if (a[u][v] == 'G' && res.fi <= mtime[u][v] && !cmp(d[u][v], res)) {
                h.push({u, v});
                d[u][v] = res;
            }
        }
    }
    return d[target.fi][target.se].fi != 2e9;
}
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   
    cin >> n >> s;
    queue <ii> bee;
    for (int i = 1; i <= n; i ++)
        for (int j = 1; j <= n; j ++) {
            cin >> a[i][j]; 
            mtime[i][j] = 2e9;
 
            if (a[i][j] == 'H') 
                bee.push({i, j}), mtime[i][j] = 0;
 
            if (a[i][j] == 'M')
                a[i][j] = 'G', start = {i, j};
 
            if (a[i][j] == 'D') 
                a[i][j] = 'G', target = {i, j};
        }
 
    while (!bee.empty()) {
        auto [x, y] = bee.front(); bee.pop();
        int res = mtime[x][y] + 1;
 
        for (int j = 0; j <= 3; j ++) {
            int u = x + dx[j];
            int v = y + dy[j];
            if (a[u][v] == 'G' && mtime[u][v] > res) {
                bee.push({u, v});
                mtime[u][v] = res;
            }
        }
    }
 
    int l = 0, r = 2e3;
    while (l < r) {
        int mid = l + (r - l + 1) / 2;
        if (check(mid)) l = mid;
        else r = mid - 1;
    }
    cout << (check(l) ? l : -1);
}
/*
     /\_/\ zzZ
    (= -_-)
    / >u  >u
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Correct 0 ms 340 KB Output is correct
6 Incorrect 1 ms 340 KB Output isn't correct
7 Runtime error 179 ms 65536 KB Execution killed with signal 9
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Incorrect 1 ms 852 KB Output isn't correct
13 Runtime error 277 ms 65536 KB Execution killed with signal 9
14 Runtime error 268 ms 65536 KB Execution killed with signal 9
15 Correct 0 ms 468 KB Output is correct
16 Correct 0 ms 468 KB Output is correct
17 Correct 0 ms 468 KB Output is correct
18 Correct 0 ms 468 KB Output is correct
19 Correct 0 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 1 ms 724 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 852 KB Output is correct
27 Incorrect 1 ms 852 KB Output isn't correct
28 Correct 1 ms 852 KB Output is correct
29 Incorrect 1 ms 852 KB Output isn't correct
30 Correct 1 ms 852 KB Output is correct
31 Incorrect 1 ms 980 KB Output isn't correct
32 Correct 1 ms 980 KB Output is correct
33 Incorrect 11 ms 3796 KB Output isn't correct
34 Incorrect 13 ms 3856 KB Output isn't correct
35 Runtime error 190 ms 65536 KB Execution killed with signal 9
36 Incorrect 13 ms 4420 KB Output isn't correct
37 Incorrect 20 ms 4416 KB Output isn't correct
38 Runtime error 195 ms 65536 KB Execution killed with signal 9
39 Incorrect 17 ms 4820 KB Output isn't correct
40 Incorrect 21 ms 4932 KB Output isn't correct
41 Runtime error 182 ms 65536 KB Execution killed with signal 9
42 Incorrect 20 ms 5436 KB Output isn't correct
43 Incorrect 25 ms 5332 KB Output isn't correct
44 Runtime error 182 ms 65536 KB Execution killed with signal 9
45 Incorrect 25 ms 5844 KB Output isn't correct
46 Incorrect 31 ms 5956 KB Output isn't correct
47 Runtime error 178 ms 65536 KB Execution killed with signal 9
48 Incorrect 29 ms 6396 KB Output isn't correct
49 Incorrect 37 ms 6452 KB Output isn't correct
50 Runtime error 207 ms 65536 KB Execution killed with signal 9
51 Incorrect 34 ms 6948 KB Output isn't correct
52 Incorrect 42 ms 6868 KB Output isn't correct
53 Runtime error 213 ms 65540 KB Execution killed with signal 9
54 Incorrect 38 ms 7380 KB Output isn't correct
55 Incorrect 48 ms 7380 KB Output isn't correct
56 Runtime error 180 ms 65536 KB Execution killed with signal 9
57 Incorrect 45 ms 7924 KB Output isn't correct
58 Incorrect 71 ms 7964 KB Output isn't correct
59 Runtime error 186 ms 65536 KB Execution killed with signal 9
60 Incorrect 51 ms 8420 KB Output isn't correct
61 Incorrect 65 ms 8436 KB Output isn't correct
62 Runtime error 191 ms 65536 KB Execution killed with signal 9
63 Correct 94 ms 8576 KB Output is correct
64 Correct 142 ms 8404 KB Output is correct
65 Correct 140 ms 8484 KB Output is correct
66 Correct 123 ms 8488 KB Output is correct
67 Correct 98 ms 8480 KB Output is correct
68 Correct 44 ms 8512 KB Output is correct
69 Correct 45 ms 8528 KB Output is correct
70 Correct 37 ms 8504 KB Output is correct
71 Correct 32 ms 8496 KB Output is correct
72 Incorrect 29 ms 8524 KB Output isn't correct
73 Runtime error 218 ms 65536 KB Execution killed with signal 9
74 Runtime error 185 ms 65536 KB Execution killed with signal 9
75 Runtime error 180 ms 65536 KB Execution killed with signal 9
76 Runtime error 176 ms 65536 KB Execution killed with signal 9
77 Runtime error 182 ms 65536 KB Execution killed with signal 9
78 Runtime error 179 ms 65536 KB Execution killed with signal 9
79 Runtime error 177 ms 65536 KB Execution killed with signal 9
80 Runtime error 187 ms 65536 KB Execution killed with signal 9
81 Runtime error 181 ms 65536 KB Execution killed with signal 9
82 Runtime error 181 ms 65536 KB Execution killed with signal 9
83 Runtime error 184 ms 65536 KB Execution killed with signal 9
84 Runtime error 185 ms 65536 KB Execution killed with signal 9
85 Runtime error 183 ms 65536 KB Execution killed with signal 9
86 Runtime error 181 ms 65536 KB Execution killed with signal 9
87 Runtime error 188 ms 65536 KB Execution killed with signal 9
88 Runtime error 191 ms 65536 KB Execution killed with signal 9
89 Runtime error 179 ms 65536 KB Execution killed with signal 9
90 Runtime error 182 ms 65536 KB Execution killed with signal 9
91 Runtime error 182 ms 65536 KB Execution killed with signal 9
92 Runtime error 193 ms 65536 KB Execution killed with signal 9