답안 #1117289

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1117289 2024-11-23T08:36:14 Z DON_F Mecho (IOI09_mecho) C++14
84 / 100
142 ms 7248 KB
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define all(x) x.begin(), x.end()
#define L(i, b, e) for (int i = b; i < e; ++i)
#define R(i, b, e) for (int i = b; i >= e; --i)
#define pb emplace_back
#define vi vector<int>
#define sz(x) ((int) x.size())
const int N = 8e2 + 7, Mx = 1e9 + 9;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
int n, s;
string a[N];
int dis1[N][N], dis2[N][N];
pair<int, int> st, d;
bool in(int x, int y){
    return (x >= 0 && y >= 0 && x < n && y < n && a[x][y] != 'T');
}
int work(int m){
    L(i, 0, n)L(j, 0, n)dis2[i][j] = Mx;
    queue<tuple<int, int, int>> q;
    q.push({st.first, st.second, s});
    dis2[st.first][st.second] = m;
    while (!q.empty()){
        auto [x, y, p] = q.front();
        q.pop();
        if (p == 0 && dis2[x][y] >= dis1[x][y])continue;
        if (p == 0)p = s;
        L(i, 0, 4){
            int nx = x + dx[i], ny = y + dy[i];
            if (in(nx, ny) && dis2[x][y] + (p == s) <= dis1[nx][ny] && dis2[nx][ny] == Mx){
                q.push({nx, ny, p - 1});
                dis2[nx][ny] = dis2[x][y] + (p == s);
            }
        }
    }
    return (dis2[d.first][d.second] != Mx);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> s;
    L(i, 0, n){
        cin >> a[i];
    }
    L(i, 0, n)L(j, 0, n)dis1[i][j] = dis2[i][j] = Mx;
    queue<pair<int, int>> q;
    L(i, 0, n){
        L(j, 0, n){
            if (a[i][j] == 'H'){
                q.push({i, j});
                dis1[i][j] = 0;
            }else if (a[i][j] == 'M'){
                st = {i, j};
            }else if (a[i][j] == 'D'){
                d = {i, j};
            }
        }
    }
    while (!q.empty()){
        auto [x, y] = q.front();
        q.pop();
        L(i, 0, 4){
            int nx = x + dx[i], ny = y + dy[i];
            if (in(nx, ny) && a[nx][ny] != 'D' && dis1[nx][ny] == Mx){
                q.push({nx, ny});
                dis1[nx][ny] = dis1[x][y] + 1;
            }
        }
    }
    int lo = 0, hi = n * n, ans = -1;
    while (lo <= hi){
        int mid = lo + (hi - lo) / 2;
        if (work(mid)){
            ans = mid;
            lo = mid + 1;
        }else{
            hi = mid - 1;
        }
    }
    cout << ans;
}



Compilation message

mecho.cpp: In function 'int work(int)':
mecho.cpp:25:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |         auto [x, y, p] = q.front();
      |              ^
mecho.cpp: In function 'int main()':
mecho.cpp:62:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   62 |         auto [x, y] = q.front();
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2552 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2556 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 66 ms 6736 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2540 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2432 KB Output is correct
12 Incorrect 2 ms 2640 KB Output isn't correct
13 Incorrect 1 ms 2808 KB Output isn't correct
14 Correct 1 ms 2640 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2540 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2640 KB Output is correct
20 Correct 1 ms 2640 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 1 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 2 ms 2740 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 1 ms 2640 KB Output is correct
29 Correct 1 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 1 ms 2640 KB Output is correct
32 Correct 2 ms 2812 KB Output is correct
33 Correct 5 ms 3664 KB Output is correct
34 Correct 5 ms 3692 KB Output is correct
35 Correct 15 ms 3676 KB Output is correct
36 Correct 5 ms 4944 KB Output is correct
37 Correct 6 ms 3920 KB Output is correct
38 Correct 20 ms 3924 KB Output is correct
39 Correct 7 ms 4176 KB Output is correct
40 Correct 9 ms 4208 KB Output is correct
41 Correct 28 ms 4176 KB Output is correct
42 Correct 7 ms 5200 KB Output is correct
43 Correct 8 ms 4628 KB Output is correct
44 Correct 33 ms 4432 KB Output is correct
45 Correct 10 ms 4688 KB Output is correct
46 Correct 10 ms 4688 KB Output is correct
47 Correct 37 ms 4896 KB Output is correct
48 Correct 10 ms 5200 KB Output is correct
49 Correct 11 ms 5172 KB Output is correct
50 Correct 41 ms 5200 KB Output is correct
51 Correct 12 ms 5712 KB Output is correct
52 Correct 13 ms 5780 KB Output is correct
53 Correct 52 ms 5712 KB Output is correct
54 Correct 14 ms 6224 KB Output is correct
55 Correct 15 ms 6224 KB Output is correct
56 Correct 61 ms 6224 KB Output is correct
57 Correct 17 ms 6644 KB Output is correct
58 Correct 17 ms 6648 KB Output is correct
59 Correct 73 ms 6480 KB Output is correct
60 Correct 19 ms 6736 KB Output is correct
61 Correct 20 ms 6856 KB Output is correct
62 Correct 94 ms 6736 KB Output is correct
63 Correct 79 ms 6736 KB Output is correct
64 Correct 142 ms 6628 KB Output is correct
65 Correct 111 ms 6736 KB Output is correct
66 Correct 87 ms 6736 KB Output is correct
67 Correct 83 ms 6736 KB Output is correct
68 Correct 36 ms 6736 KB Output is correct
69 Correct 35 ms 6736 KB Output is correct
70 Correct 28 ms 6736 KB Output is correct
71 Correct 31 ms 6736 KB Output is correct
72 Incorrect 30 ms 6736 KB Output isn't correct
73 Incorrect 28 ms 7248 KB Output isn't correct
74 Correct 39 ms 7240 KB Output is correct
75 Correct 52 ms 6992 KB Output is correct
76 Correct 41 ms 6992 KB Output is correct
77 Correct 42 ms 7160 KB Output is correct
78 Correct 51 ms 7020 KB Output is correct
79 Correct 40 ms 6992 KB Output is correct
80 Correct 41 ms 6872 KB Output is correct
81 Correct 46 ms 6992 KB Output is correct
82 Correct 46 ms 6992 KB Output is correct
83 Correct 53 ms 6992 KB Output is correct
84 Correct 47 ms 7020 KB Output is correct
85 Correct 51 ms 6992 KB Output is correct
86 Correct 52 ms 6992 KB Output is correct
87 Correct 51 ms 6992 KB Output is correct
88 Correct 53 ms 6868 KB Output is correct
89 Correct 54 ms 7020 KB Output is correct
90 Correct 56 ms 7184 KB Output is correct
91 Correct 55 ms 7160 KB Output is correct
92 Correct 59 ms 7000 KB Output is correct