답안 #221433

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
221433 2020-04-10T04:35:02 Z tatyam Mecho (IOI09_mecho) C++17
72 / 100
1000 ms 9848 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int INF = 0x3fffffff;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
#define name2(a,b,c,...) c
#define rep1(b) for(int i = 0; i < b; i++)
#define rep2(i,b) for(int i = 0; i < b; i++)
#define rep(...) name2(__VA_ARGS__,rep2,rep1)(__VA_ARGS__)
#define each(i,a) for(auto&& i : a)
template<class T, class U> bool chmin(T& a, const U& b){ if(a > b){ a = b; return 1; } return 0; }
template<class T, class U> bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; }


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, s;
    cin >> n >> s;
    vector<string> a(n);
    each(i, a) cin >> i;
    vector<vector<int>> cost(n, vector<int>(n, INF));
    queue<pii> q;
    rep(n) rep(j, n) if(a[i][j] == 'H'){
        cost[i][j] = 0;
        q.emplace(i, j);
    }
    while(q.size()){
        auto [x, y] = q.front();
        q.pop();
        rep(i, 4){
            int x2 = x + dx[i], y2 = y + dy[i];
            if(x2 < 0 || y2 < 0 || x2 >= n || y2 >= n || a[x2][y2] != 'G') continue;
            if(chmin(cost[x2][y2], cost[x][y] + 1)) q.emplace(x2, y2);
        }
    }
    vector<vector<pii>> ans(n, vector<pii>(n));
    rep(n) rep(j, n) if(a[i][j] == 'M'){
        ans[i][j].first = cost[i][j];
        q.emplace(i, j);
    }
    while(q.size()){
        auto [x, y] = q.front();
        q.pop();
        rep(i, 4){
            int x2 = x + dx[i], y2 = y + dy[i];
            if(x2 < 0 || y2 < 0 || x2 >= n || y2 >= n || a[x2][y2] == 'T') continue;
            pii a = ans[x][y];
            a.second--;
            chmin(a.first, cost[x2][y2] + a.second / s);
            if(chmax(ans[x2][y2], a)) q.emplace(x2, y2);
        }
    }
    rep(n) rep(j, n) if(a[i][j] == 'D') cout << ans[i][j].first - 1 << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 64 ms 9208 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Incorrect 5 ms 384 KB Output isn't correct
13 Incorrect 5 ms 384 KB Output isn't correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 512 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 9 ms 2048 KB Output is correct
34 Correct 10 ms 2048 KB Output is correct
35 Correct 178 ms 2188 KB Output is correct
36 Correct 10 ms 2560 KB Output is correct
37 Correct 11 ms 2560 KB Output is correct
38 Correct 257 ms 2680 KB Output is correct
39 Correct 12 ms 3200 KB Output is correct
40 Correct 13 ms 3200 KB Output is correct
41 Correct 381 ms 3448 KB Output is correct
42 Correct 13 ms 3840 KB Output is correct
43 Correct 15 ms 3840 KB Output is correct
44 Correct 519 ms 3960 KB Output is correct
45 Correct 15 ms 4608 KB Output is correct
46 Correct 17 ms 4608 KB Output is correct
47 Correct 683 ms 4856 KB Output is correct
48 Correct 17 ms 5376 KB Output is correct
49 Correct 19 ms 5376 KB Output is correct
50 Correct 920 ms 5884 KB Output is correct
51 Correct 19 ms 6272 KB Output is correct
52 Correct 22 ms 6272 KB Output is correct
53 Execution timed out 1092 ms 6652 KB Time limit exceeded
54 Correct 21 ms 7168 KB Output is correct
55 Correct 25 ms 7168 KB Output is correct
56 Execution timed out 1088 ms 7544 KB Time limit exceeded
57 Correct 23 ms 8192 KB Output is correct
58 Correct 27 ms 8192 KB Output is correct
59 Execution timed out 1091 ms 8836 KB Time limit exceeded
60 Correct 26 ms 9208 KB Output is correct
61 Correct 30 ms 9216 KB Output is correct
62 Execution timed out 1093 ms 9848 KB Time limit exceeded
63 Correct 53 ms 9208 KB Output is correct
64 Correct 56 ms 9208 KB Output is correct
65 Correct 56 ms 9208 KB Output is correct
66 Correct 56 ms 9376 KB Output is correct
67 Correct 46 ms 9208 KB Output is correct
68 Correct 42 ms 9208 KB Output is correct
69 Correct 47 ms 9208 KB Output is correct
70 Correct 41 ms 9208 KB Output is correct
71 Correct 42 ms 9208 KB Output is correct
72 Incorrect 45 ms 9208 KB Output isn't correct
73 Incorrect 51 ms 9208 KB Output isn't correct
74 Correct 101 ms 9208 KB Output is correct
75 Correct 55 ms 9208 KB Output is correct
76 Correct 52 ms 9336 KB Output is correct
77 Correct 52 ms 9208 KB Output is correct
78 Correct 45 ms 9344 KB Output is correct
79 Correct 391 ms 9456 KB Output is correct
80 Correct 65 ms 9216 KB Output is correct
81 Correct 58 ms 9344 KB Output is correct
82 Correct 118 ms 9336 KB Output is correct
83 Correct 48 ms 9208 KB Output is correct
84 Correct 119 ms 9208 KB Output is correct
85 Correct 180 ms 9336 KB Output is correct
86 Correct 230 ms 9336 KB Output is correct
87 Correct 70 ms 9216 KB Output is correct
88 Correct 141 ms 9336 KB Output is correct
89 Correct 472 ms 9720 KB Output is correct
90 Correct 56 ms 9208 KB Output is correct
91 Correct 79 ms 9208 KB Output is correct
92 Correct 57 ms 9208 KB Output is correct