답안 #789652

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
789652 2023-07-21T16:04:39 Z phongcd Mecho (IOI09_mecho) C++14
13 / 100
295 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 = 1;
}

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 = 1, r = 1e6;
    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:82:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   82 |         auto [x, y] = bee.front(); bee.pop();
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Incorrect 0 ms 340 KB Output isn't correct
3 Incorrect 0 ms 328 KB Output isn't correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Incorrect 0 ms 340 KB Output isn't correct
6 Incorrect 0 ms 340 KB Output isn't correct
7 Runtime error 185 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 460 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 295 ms 65536 KB Execution killed with signal 9
14 Runtime error 267 ms 65536 KB Execution killed with signal 9
15 Incorrect 1 ms 468 KB Output isn't correct
16 Correct 1 ms 468 KB Output is correct
17 Incorrect 1 ms 456 KB Output isn't correct
18 Correct 1 ms 468 KB Output is correct
19 Incorrect 1 ms 468 KB Output isn't correct
20 Correct 1 ms 464 KB Output is correct
21 Incorrect 1 ms 596 KB Output isn't correct
22 Correct 1 ms 596 KB Output is correct
23 Incorrect 1 ms 724 KB Output isn't correct
24 Correct 1 ms 724 KB Output is correct
25 Incorrect 1 ms 852 KB Output isn't 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 848 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 984 KB Output is correct
33 Incorrect 6 ms 3924 KB Output isn't correct
34 Correct 8 ms 3928 KB Output is correct
35 Runtime error 203 ms 65536 KB Execution killed with signal 9
36 Incorrect 7 ms 4564 KB Output isn't correct
37 Correct 9 ms 4564 KB Output is correct
38 Runtime error 184 ms 65536 KB Execution killed with signal 9
39 Incorrect 10 ms 5128 KB Output isn't correct
40 Correct 11 ms 5132 KB Output is correct
41 Runtime error 183 ms 65536 KB Execution killed with signal 9
42 Incorrect 11 ms 5588 KB Output isn't correct
43 Correct 11 ms 5588 KB Output is correct
44 Runtime error 184 ms 65536 KB Execution killed with signal 9
45 Incorrect 12 ms 6228 KB Output isn't correct
46 Correct 12 ms 6228 KB Output is correct
47 Runtime error 183 ms 65536 KB Execution killed with signal 9
48 Incorrect 14 ms 6776 KB Output isn't correct
49 Correct 14 ms 6740 KB Output is correct
50 Runtime error 197 ms 65536 KB Execution killed with signal 9
51 Incorrect 16 ms 7288 KB Output isn't correct
52 Correct 16 ms 7300 KB Output is correct
53 Runtime error 188 ms 65536 KB Execution killed with signal 9
54 Incorrect 20 ms 7876 KB Output isn't correct
55 Correct 20 ms 7892 KB Output is correct
56 Runtime error 180 ms 65536 KB Execution killed with signal 9
57 Incorrect 20 ms 8416 KB Output isn't correct
58 Correct 21 ms 8536 KB Output is correct
59 Runtime error 220 ms 65536 KB Execution killed with signal 9
60 Incorrect 23 ms 9132 KB Output isn't correct
61 Correct 22 ms 9132 KB Output is correct
62 Runtime error 187 ms 65536 KB Execution killed with signal 9
63 Incorrect 88 ms 9044 KB Output isn't correct
64 Correct 143 ms 9068 KB Output is correct
65 Correct 142 ms 9112 KB Output is correct
66 Incorrect 129 ms 9108 KB Output isn't correct
67 Correct 100 ms 9116 KB Output is correct
68 Incorrect 54 ms 9232 KB Output isn't correct
69 Correct 50 ms 9132 KB Output is correct
70 Correct 42 ms 9132 KB Output is correct
71 Correct 39 ms 9124 KB Output is correct
72 Incorrect 40 ms 9124 KB Output isn't correct
73 Runtime error 221 ms 65536 KB Execution killed with signal 9
74 Runtime error 181 ms 65536 KB Execution killed with signal 9
75 Runtime error 191 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 192 ms 65536 KB Execution killed with signal 9
79 Runtime error 179 ms 65536 KB Execution killed with signal 9
80 Runtime error 183 ms 65536 KB Execution killed with signal 9
81 Runtime error 193 ms 65536 KB Execution killed with signal 9
82 Runtime error 176 ms 65536 KB Execution killed with signal 9
83 Runtime error 195 ms 65536 KB Execution killed with signal 9
84 Runtime error 184 ms 65536 KB Execution killed with signal 9
85 Runtime error 208 ms 65536 KB Execution killed with signal 9
86 Runtime error 191 ms 65536 KB Execution killed with signal 9
87 Runtime error 186 ms 65536 KB Execution killed with signal 9
88 Runtime error 178 ms 65536 KB Execution killed with signal 9
89 Runtime error 186 ms 65536 KB Execution killed with signal 9
90 Runtime error 185 ms 65536 KB Execution killed with signal 9
91 Runtime error 180 ms 65536 KB Execution killed with signal 9
92 Runtime error 201 ms 65536 KB Execution killed with signal 9