답안 #789660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789660 2023-07-21T16:30:27 Z phongcd Mecho (IOI09_mecho) C++14
27 / 100
277 ms 65536 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
*/

Compilation message

mecho.cpp: In function 'bool check(int)':
mecho.cpp:44:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   44 |         auto [x, y] = h.front(); h.pop();
      |              ^
mecho.cpp: In function 'int main()':
mecho.cpp:81:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   81 |         auto [x, y] = bee.front(); bee.pop();
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Correct 1 ms 340 KB Output is correct
6 Incorrect 0 ms 340 KB Output isn't correct
7 Runtime error 178 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 1 ms 340 KB Output is correct
11 Correct 1 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 262 ms 65536 KB Execution killed with signal 9
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 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 848 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Incorrect 1 ms 848 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 976 KB Output isn't correct
32 Correct 1 ms 980 KB Output is correct
33 Incorrect 10 ms 3924 KB Output isn't correct
34 Incorrect 13 ms 3928 KB Output isn't correct
35 Runtime error 180 ms 65536 KB Execution killed with signal 9
36 Incorrect 13 ms 4564 KB Output isn't correct
37 Incorrect 17 ms 4580 KB Output isn't correct
38 Runtime error 181 ms 65536 KB Execution killed with signal 9
39 Incorrect 17 ms 5004 KB Output isn't correct
40 Incorrect 20 ms 5128 KB Output isn't correct
41 Runtime error 182 ms 65536 KB Execution killed with signal 9
42 Incorrect 20 ms 5688 KB Output isn't correct
43 Incorrect 25 ms 5648 KB Output isn't correct
44 Runtime error 181 ms 65536 KB Execution killed with signal 9
45 Incorrect 24 ms 6100 KB Output isn't correct
46 Incorrect 30 ms 6080 KB Output isn't correct
47 Runtime error 177 ms 65536 KB Execution killed with signal 9
48 Incorrect 29 ms 6608 KB Output isn't correct
49 Incorrect 36 ms 6692 KB Output isn't correct
50 Runtime error 177 ms 65536 KB Execution killed with signal 9
51 Incorrect 33 ms 7124 KB Output isn't correct
52 Incorrect 42 ms 7208 KB Output isn't correct
53 Runtime error 184 ms 65536 KB Execution killed with signal 9
54 Incorrect 39 ms 7720 KB Output isn't correct
55 Incorrect 48 ms 7712 KB Output isn't correct
56 Runtime error 179 ms 65536 KB Execution killed with signal 9
57 Incorrect 44 ms 8148 KB Output isn't correct
58 Incorrect 56 ms 8224 KB Output isn't correct
59 Runtime error 183 ms 65536 KB Execution killed with signal 9
60 Incorrect 50 ms 8668 KB Output isn't correct
61 Incorrect 64 ms 8740 KB Output isn't correct
62 Runtime error 185 ms 65536 KB Execution killed with signal 9
63 Correct 95 ms 8808 KB Output is correct
64 Correct 140 ms 8728 KB Output is correct
65 Correct 136 ms 8728 KB Output is correct
66 Correct 114 ms 8660 KB Output is correct
67 Correct 97 ms 8744 KB Output is correct
68 Correct 39 ms 8768 KB Output is correct
69 Correct 42 ms 8652 KB Output is correct
70 Correct 38 ms 8756 KB Output is correct
71 Correct 33 ms 8780 KB Output is correct
72 Incorrect 31 ms 8704 KB Output isn't correct
73 Runtime error 177 ms 65536 KB Execution killed with signal 9
74 Runtime error 183 ms 65536 KB Execution killed with signal 9
75 Runtime error 176 ms 65536 KB Execution killed with signal 9
76 Runtime error 176 ms 65536 KB Execution killed with signal 9
77 Runtime error 177 ms 65536 KB Execution killed with signal 9
78 Runtime error 174 ms 65536 KB Execution killed with signal 9
79 Runtime error 176 ms 65536 KB Execution killed with signal 9
80 Runtime error 179 ms 65536 KB Execution killed with signal 9
81 Runtime error 179 ms 65536 KB Execution killed with signal 9
82 Runtime error 179 ms 65536 KB Execution killed with signal 9
83 Runtime error 184 ms 65536 KB Execution killed with signal 9
84 Runtime error 186 ms 65536 KB Execution killed with signal 9
85 Runtime error 182 ms 65536 KB Execution killed with signal 9
86 Runtime error 183 ms 65536 KB Execution killed with signal 9
87 Runtime error 181 ms 65536 KB Execution killed with signal 9
88 Runtime error 177 ms 65536 KB Execution killed with signal 9
89 Runtime error 178 ms 65536 KB Execution killed with signal 9
90 Runtime error 177 ms 65536 KB Execution killed with signal 9
91 Runtime error 178 ms 65536 KB Execution killed with signal 9
92 Runtime error 180 ms 65536 KB Execution killed with signal 9