답안 #834907

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834907 2023-08-23T00:46:44 Z NoLove Mecho (IOI09_mecho) C++14
0 / 100
49 ms 65536 KB
/**
 *    author : Lăng Trọng Đạt
 *    created: 2023-08-22
**/
#include <bits/stdc++.h>
using namespace std;
#ifndef LANG_DAT
#define db(...) ;
#endif // LANG_DAT
#define int int64_t
#define mp make_pair
#define pb push_back
using pii = pair<int, int>;

const int MAXN = 1e4 + 5;
int dist[MAXN][MAXN];
char g[MAXN][MAXN];
bool vis[MAXN][MAXN];
int x_change[]{1, -1, 0, 0};
int y_change[]{0, 0, 1, -1};
int n, s;

struct Data {
    int i, j, cnt, k;
    // cnt: number of step, k: : the maximum possible number of minutes that Mecho can continue eating honey at his initial location, while still being able to get home safely.
    // @return number of minutes passed
    int t() {
        return cnt / s + (cnt % s != 0);
    }
};

bool vaild(int i, int j, int d) {
    return 0 <= i && i < n && 0 <= j && j < n &&
           !vis[i][j] && d < dist[i][j] && g[i][j] != 'T';
}

int32_t main() {
    cin.tie(0)->sync_with_stdio(0);
    if (fopen("hi.inp", "r")) {
        freopen("hi.inp", "r", stdin);
//        freopen("hi.out", "w", stdout);
    }

    cin >> n >> s;
    queue<pair<pii, int>> q;
    queue<Data> q2;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++) {
            cin >> g[i][j];
            if (g[i][j] == 'H') {
                q.push({{i, j}, 0});
            } else if (g[i][j] == 'M') {
                q2.push({i, j, 0, (int)1e18});
            }
        }
    memset(dist, 0x3f3f3f, sizeof(dist));
    while (q.size()) {
        auto[p, d] = q.front(); q.pop();
        auto[i, j] = p;
        if (vaild(i, j, d)) {
            if (g[i][j] == 'D') continue;
            dist[i][j] = d;
            for (int k = 0; k < 4; k++) {
                q.push({{i + x_change[k], j + y_change[k]}, d + 1});
            }
            db(i, j, dist[i][j], g[i][j])
        }
    }

    while (q2.size()) {
        Data x = q2.front(); q2.pop();
        if (vaild(x.i, x.j, x.t()) && x.k >= 0) {
            vis[x.i][x.j] = true;
            x.k = min(x.k, dist[x.i][x.j] - x.t());
            db(x.i, x.j, x.k)
            for (int k = 0; k < 4; k++) {
                q2.push({x.i + x_change[k], x.j + y_change[k], x.cnt + 1, x.k});
            }
            if (g[x.i][x.j] == 'D') {
                cout << x.k;
                return 0;
            }
        }
    }
    cout << -1;
}

Compilation message

mecho.cpp: In function 'int32_t main()':
mecho.cpp:58:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   58 |         auto[p, d] = q.front(); q.pop();
      |             ^
mecho.cpp:59:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   59 |         auto[i, j] = p;
      |             ^
mecho.cpp:40:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |         freopen("hi.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 30 ms 65536 KB Execution killed with signal 9
2 Runtime error 27 ms 65536 KB Execution killed with signal 9
3 Runtime error 26 ms 65536 KB Execution killed with signal 9
4 Runtime error 27 ms 65536 KB Execution killed with signal 9
5 Runtime error 26 ms 65536 KB Execution killed with signal 9
6 Runtime error 29 ms 65536 KB Execution killed with signal 9
7 Runtime error 44 ms 65536 KB Execution killed with signal 9
8 Runtime error 28 ms 65536 KB Execution killed with signal 9
9 Runtime error 40 ms 65536 KB Execution killed with signal 9
10 Runtime error 37 ms 65536 KB Execution killed with signal 9
11 Runtime error 28 ms 65536 KB Execution killed with signal 9
12 Runtime error 32 ms 65536 KB Execution killed with signal 9
13 Runtime error 28 ms 65536 KB Execution killed with signal 9
14 Runtime error 28 ms 65536 KB Execution killed with signal 9
15 Runtime error 27 ms 65536 KB Execution killed with signal 9
16 Runtime error 36 ms 65536 KB Execution killed with signal 9
17 Runtime error 29 ms 65536 KB Execution killed with signal 9
18 Runtime error 28 ms 65536 KB Execution killed with signal 9
19 Runtime error 29 ms 65536 KB Execution killed with signal 9
20 Runtime error 44 ms 65536 KB Execution killed with signal 9
21 Runtime error 28 ms 65536 KB Execution killed with signal 9
22 Runtime error 28 ms 65536 KB Execution killed with signal 9
23 Runtime error 25 ms 65536 KB Execution killed with signal 9
24 Runtime error 27 ms 65536 KB Execution killed with signal 9
25 Runtime error 28 ms 65536 KB Execution killed with signal 9
26 Runtime error 41 ms 65536 KB Execution killed with signal 9
27 Runtime error 29 ms 65536 KB Execution killed with signal 9
28 Runtime error 28 ms 65536 KB Execution killed with signal 9
29 Runtime error 28 ms 65536 KB Execution killed with signal 9
30 Runtime error 27 ms 65536 KB Execution killed with signal 9
31 Runtime error 29 ms 65536 KB Execution killed with signal 9
32 Runtime error 29 ms 65536 KB Execution killed with signal 9
33 Runtime error 33 ms 65536 KB Execution killed with signal 9
34 Runtime error 30 ms 65536 KB Execution killed with signal 9
35 Runtime error 33 ms 65536 KB Execution killed with signal 9
36 Runtime error 30 ms 65536 KB Execution killed with signal 9
37 Runtime error 27 ms 65536 KB Execution killed with signal 9
38 Runtime error 37 ms 65536 KB Execution killed with signal 9
39 Runtime error 46 ms 65536 KB Execution killed with signal 9
40 Runtime error 30 ms 65536 KB Execution killed with signal 9
41 Runtime error 31 ms 65536 KB Execution killed with signal 9
42 Runtime error 36 ms 65536 KB Execution killed with signal 9
43 Runtime error 37 ms 65536 KB Execution killed with signal 9
44 Runtime error 29 ms 65536 KB Execution killed with signal 9
45 Runtime error 31 ms 65536 KB Execution killed with signal 9
46 Runtime error 46 ms 65536 KB Execution killed with signal 9
47 Runtime error 31 ms 65536 KB Execution killed with signal 9
48 Runtime error 37 ms 65536 KB Execution killed with signal 9
49 Runtime error 33 ms 65536 KB Execution killed with signal 9
50 Runtime error 31 ms 65536 KB Execution killed with signal 9
51 Runtime error 32 ms 65536 KB Execution killed with signal 9
52 Runtime error 42 ms 65536 KB Execution killed with signal 9
53 Runtime error 33 ms 65536 KB Execution killed with signal 9
54 Runtime error 44 ms 65536 KB Execution killed with signal 9
55 Runtime error 33 ms 65536 KB Execution killed with signal 9
56 Runtime error 32 ms 65536 KB Execution killed with signal 9
57 Runtime error 43 ms 65536 KB Execution killed with signal 9
58 Runtime error 33 ms 65536 KB Execution killed with signal 9
59 Runtime error 34 ms 65536 KB Execution killed with signal 9
60 Runtime error 39 ms 65536 KB Execution killed with signal 9
61 Runtime error 34 ms 65536 KB Execution killed with signal 9
62 Runtime error 35 ms 65536 KB Execution killed with signal 9
63 Runtime error 36 ms 65536 KB Execution killed with signal 9
64 Runtime error 32 ms 65536 KB Execution killed with signal 9
65 Runtime error 49 ms 65536 KB Execution killed with signal 9
66 Runtime error 34 ms 65536 KB Execution killed with signal 9
67 Runtime error 32 ms 65536 KB Execution killed with signal 9
68 Runtime error 36 ms 65536 KB Execution killed with signal 9
69 Runtime error 37 ms 65536 KB Execution killed with signal 9
70 Runtime error 33 ms 65536 KB Execution killed with signal 9
71 Runtime error 46 ms 65536 KB Execution killed with signal 9
72 Runtime error 32 ms 65536 KB Execution killed with signal 9
73 Runtime error 34 ms 65536 KB Execution killed with signal 9
74 Runtime error 38 ms 65536 KB Execution killed with signal 9
75 Runtime error 33 ms 65536 KB Execution killed with signal 9
76 Runtime error 32 ms 65536 KB Execution killed with signal 9
77 Runtime error 31 ms 65536 KB Execution killed with signal 9
78 Runtime error 45 ms 65536 KB Execution killed with signal 9
79 Runtime error 35 ms 65536 KB Execution killed with signal 9
80 Runtime error 33 ms 65536 KB Execution killed with signal 9
81 Runtime error 31 ms 65536 KB Execution killed with signal 9
82 Runtime error 34 ms 65536 KB Execution killed with signal 9
83 Runtime error 34 ms 65536 KB Execution killed with signal 9
84 Runtime error 35 ms 65536 KB Execution killed with signal 9
85 Runtime error 33 ms 65536 KB Execution killed with signal 9
86 Runtime error 34 ms 65536 KB Execution killed with signal 9
87 Runtime error 33 ms 65536 KB Execution killed with signal 9
88 Runtime error 34 ms 65536 KB Execution killed with signal 9
89 Runtime error 34 ms 65536 KB Execution killed with signal 9
90 Runtime error 35 ms 65536 KB Execution killed with signal 9
91 Runtime error 34 ms 65536 KB Execution killed with signal 9
92 Runtime error 35 ms 65536 KB Execution killed with signal 9