Submission #1016211

# Submission time Handle Problem Language Result Execution time Memory
1016211 2024-07-07T13:58:38 Z socpite Mecho (IOI09_mecho) C++14
100 / 100
121 ms 24920 KB
#include<bits/stdc++.h>
using namespace std;

const int maxn = 805;
const int INF = 1e9;

const pair<int, int> mv[4] = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};

int n, s;
char board[maxn][maxn];

bool inb(int a, int b){
    return a >= 1 && a <= n && b >= 1 && b <= n;
}

bool chk(int a, int b){
    return inb(a, b) && board[a][b] != 'D' && board[a][b] != 'T';
}

int dm[maxn][maxn], db[maxn][maxn]; 
int val[maxn][maxn];
vector<pair<int, int>> pq[maxn*maxn];

bool chk(int dist){
    queue<pair<int, int>> q;
    memset(dm, -1, sizeof(dm));
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++)if(board[i][j] == 'M'){
            dm[i][j] = 0;
            q.push({i, j});
        }
    }
    while(!q.empty()){
        auto x = q.front();
        q.pop();
        if(dm[x.first][x.second]/s + dist >= db[x.first][x.second])continue;
        for(auto v: mv){
            int nx = x.first + v.first, ny = x.second + v.second;
            if(inb(nx, ny) && board[nx][ny] == 'D')return true;
            if(dm[nx][ny] == -1 && chk(nx, ny)){
                dm[nx][ny] = dm[x.first][x.second] + 1;
                q.push({nx, ny});
            }
        }
    }
    return false;

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> s;
    queue<pair<int, int>> q;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            cin >> board[i][j];
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(board[i][j] == 'H')q.push({i, j});
            else db[i][j] = INF;
        }
    }
    while(!q.empty()){
        auto x = q.front();
        q.pop();
        for(auto v: mv){
            int nx = x.first + v.first, ny = x.second + v.second;
            if(db[nx][ny] == INF && chk(nx, ny)){
                db[nx][ny] = db[x.first][x.second] + 1;
                q.push({nx, ny});
            }
        }
    }
    int l = -1, r = maxn*maxn;
    while(l < r){
        int mid = (l+r+1)>>1;
        if(chk(mid))l = mid;
        else r = mid - 1;
    }
    cout << l;

}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 23204 KB Output is correct
2 Correct 4 ms 23128 KB Output is correct
3 Correct 4 ms 23132 KB Output is correct
4 Correct 4 ms 23128 KB Output is correct
5 Correct 4 ms 23132 KB Output is correct
6 Correct 4 ms 23132 KB Output is correct
7 Correct 53 ms 24672 KB Output is correct
8 Correct 4 ms 23132 KB Output is correct
9 Correct 4 ms 23132 KB Output is correct
10 Correct 4 ms 23132 KB Output is correct
11 Correct 4 ms 23132 KB Output is correct
12 Correct 4 ms 23132 KB Output is correct
13 Correct 4 ms 23132 KB Output is correct
14 Correct 4 ms 23132 KB Output is correct
15 Correct 4 ms 23132 KB Output is correct
16 Correct 4 ms 23168 KB Output is correct
17 Correct 5 ms 23132 KB Output is correct
18 Correct 4 ms 23200 KB Output is correct
19 Correct 4 ms 23128 KB Output is correct
20 Correct 5 ms 23132 KB Output is correct
21 Correct 4 ms 23132 KB Output is correct
22 Correct 4 ms 23132 KB Output is correct
23 Correct 4 ms 23132 KB Output is correct
24 Correct 4 ms 23128 KB Output is correct
25 Correct 5 ms 23196 KB Output is correct
26 Correct 6 ms 23132 KB Output is correct
27 Correct 4 ms 23132 KB Output is correct
28 Correct 4 ms 23348 KB Output is correct
29 Correct 4 ms 23132 KB Output is correct
30 Correct 4 ms 23132 KB Output is correct
31 Correct 4 ms 23132 KB Output is correct
32 Correct 4 ms 23132 KB Output is correct
33 Correct 6 ms 23644 KB Output is correct
34 Correct 6 ms 23604 KB Output is correct
35 Correct 14 ms 23692 KB Output is correct
36 Correct 8 ms 23644 KB Output is correct
37 Correct 7 ms 23644 KB Output is correct
38 Correct 17 ms 23644 KB Output is correct
39 Correct 8 ms 23640 KB Output is correct
40 Correct 8 ms 23644 KB Output is correct
41 Correct 21 ms 23760 KB Output is correct
42 Correct 12 ms 23900 KB Output is correct
43 Correct 9 ms 23900 KB Output is correct
44 Correct 31 ms 24144 KB Output is correct
45 Correct 10 ms 23900 KB Output is correct
46 Correct 10 ms 24016 KB Output is correct
47 Correct 31 ms 23900 KB Output is correct
48 Correct 15 ms 23900 KB Output is correct
49 Correct 11 ms 24036 KB Output is correct
50 Correct 36 ms 23900 KB Output is correct
51 Correct 14 ms 24152 KB Output is correct
52 Correct 14 ms 23968 KB Output is correct
53 Correct 50 ms 24156 KB Output is correct
54 Correct 15 ms 24156 KB Output is correct
55 Correct 15 ms 24152 KB Output is correct
56 Correct 56 ms 24156 KB Output is correct
57 Correct 15 ms 24412 KB Output is correct
58 Correct 17 ms 24408 KB Output is correct
59 Correct 57 ms 24420 KB Output is correct
60 Correct 17 ms 24412 KB Output is correct
61 Correct 18 ms 24548 KB Output is correct
62 Correct 71 ms 24452 KB Output is correct
63 Correct 79 ms 24412 KB Output is correct
64 Correct 121 ms 24412 KB Output is correct
65 Correct 101 ms 24412 KB Output is correct
66 Correct 72 ms 24408 KB Output is correct
67 Correct 82 ms 24412 KB Output is correct
68 Correct 39 ms 24408 KB Output is correct
69 Correct 39 ms 24404 KB Output is correct
70 Correct 28 ms 24408 KB Output is correct
71 Correct 34 ms 24412 KB Output is correct
72 Correct 29 ms 24412 KB Output is correct
73 Correct 30 ms 24668 KB Output is correct
74 Correct 38 ms 24664 KB Output is correct
75 Correct 44 ms 24668 KB Output is correct
76 Correct 42 ms 24668 KB Output is correct
77 Correct 55 ms 24668 KB Output is correct
78 Correct 46 ms 24732 KB Output is correct
79 Correct 34 ms 24668 KB Output is correct
80 Correct 43 ms 24668 KB Output is correct
81 Correct 46 ms 24664 KB Output is correct
82 Correct 45 ms 24660 KB Output is correct
83 Correct 51 ms 24748 KB Output is correct
84 Correct 55 ms 24660 KB Output is correct
85 Correct 50 ms 24656 KB Output is correct
86 Correct 50 ms 24612 KB Output is correct
87 Correct 49 ms 24664 KB Output is correct
88 Correct 69 ms 24668 KB Output is correct
89 Correct 54 ms 24668 KB Output is correct
90 Correct 71 ms 24656 KB Output is correct
91 Correct 57 ms 24920 KB Output is correct
92 Correct 57 ms 24668 KB Output is correct