Submission #53483

# Submission time Handle Problem Language Result Execution time Memory
53483 2018-06-30T05:48:23 Z 시제연(#2016) Mecho (IOI09_mecho) C++11
100 / 100
200 ms 6536 KB
#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;
#define X first
#define Y second

const int N = 805, INF = int(1e9), dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};

int n, s, d[N][N], e[N][N], sx, sy, ex, ey;
queue<pii> q;
char b[N][N];

int f(int x){
    q.push({sx, sy});
    for(int i = 1; i <= n; i++) fill(e[i] + 1, e[i] + n + 1, INF);
    e[sx][sy] = 0;
    while(!q.empty()){
        pii c = q.front();
        q.pop();
        for(int i = 0; i < 4; i++){
            pii nx = {c.X + dx[i], c.Y + dy[i]};
            if(nx.X < 1 || nx.X > n || nx.Y < 1 || nx.Y > n) continue;
            if(b[nx.X][nx.Y] != 'G' && b[nx.X][nx.Y] != 'D') continue;
            if(e[nx.X][nx.Y] <= e[c.X][c.Y] + 1) continue;
            if((e[c.X][c.Y] + 1) / s >= d[nx.X][nx.Y] - x) continue;
            e[nx.X][nx.Y] = e[c.X][c.Y] + 1;
            q.push(nx);
        }
    }
    return (e[ex][ey] != INF);
}

int main(){
    scanf("%d%d", &n, &s);
    for(int i = 1; i <= n; i++) scanf("%s", b[i] + 1);
    for(int i = 1; i <= n; i++) fill(d[i] + 1, d[i] + n + 1, INF);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(b[i][j] == 'H'){ q.push({i, j}); d[i][j] = 0; }
            else if(b[i][j] == 'M'){ sx = i; sy = j; }
            else if(b[i][j] == 'D'){ ex = i; ey = j; }
        }
    }
    while(!q.empty()){
        pii c = q.front();
        q.pop();
        for(int i = 0; i < 4; i++){
            pii nx = {c.X + dx[i], c.Y + dy[i]};
            if(nx.X < 1 || nx.X > n || nx.Y < 1 || nx.Y > n) continue;
            if(b[nx.X][nx.Y] != 'G' && b[nx.X][nx.Y] != 'M') continue;
            if(d[nx.X][nx.Y] <= d[c.X][c.Y] + 1) continue;
            d[nx.X][nx.Y] = d[c.X][c.Y] + 1;
            q.push(nx);
        }
    }
    int l = 0, r = d[sx][sy] - 1;
    while(l <= r){
        int m = (l + r) / 2;
        if(f(m)) l = m + 1;
        else r = m - 1;
    }
    printf("%d\n", r);
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &s);
     ~~~~~^~~~~~~~~~~~~~~~
mecho.cpp:36:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; i++) scanf("%s", b[i] + 1);
                                 ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 448 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 2 ms 672 KB Output is correct
6 Correct 2 ms 672 KB Output is correct
7 Correct 107 ms 6380 KB Output is correct
8 Correct 2 ms 6380 KB Output is correct
9 Correct 2 ms 6380 KB Output is correct
10 Correct 2 ms 6380 KB Output is correct
11 Correct 3 ms 6380 KB Output is correct
12 Correct 4 ms 6380 KB Output is correct
13 Correct 2 ms 6380 KB Output is correct
14 Correct 2 ms 6380 KB Output is correct
15 Correct 2 ms 6380 KB Output is correct
16 Correct 2 ms 6380 KB Output is correct
17 Correct 2 ms 6380 KB Output is correct
18 Correct 3 ms 6380 KB Output is correct
19 Correct 2 ms 6380 KB Output is correct
20 Correct 2 ms 6380 KB Output is correct
21 Correct 3 ms 6380 KB Output is correct
22 Correct 3 ms 6380 KB Output is correct
23 Correct 2 ms 6380 KB Output is correct
24 Correct 2 ms 6380 KB Output is correct
25 Correct 2 ms 6380 KB Output is correct
26 Correct 2 ms 6380 KB Output is correct
27 Correct 3 ms 6380 KB Output is correct
28 Correct 3 ms 6380 KB Output is correct
29 Correct 3 ms 6380 KB Output is correct
30 Correct 2 ms 6380 KB Output is correct
31 Correct 3 ms 6380 KB Output is correct
32 Correct 2 ms 6380 KB Output is correct
33 Correct 8 ms 6380 KB Output is correct
34 Correct 8 ms 6380 KB Output is correct
35 Correct 33 ms 6380 KB Output is correct
36 Correct 11 ms 6380 KB Output is correct
37 Correct 10 ms 6380 KB Output is correct
38 Correct 51 ms 6380 KB Output is correct
39 Correct 10 ms 6380 KB Output is correct
40 Correct 14 ms 6380 KB Output is correct
41 Correct 38 ms 6380 KB Output is correct
42 Correct 13 ms 6380 KB Output is correct
43 Correct 13 ms 6380 KB Output is correct
44 Correct 48 ms 6380 KB Output is correct
45 Correct 17 ms 6380 KB Output is correct
46 Correct 15 ms 6380 KB Output is correct
47 Correct 58 ms 6380 KB Output is correct
48 Correct 16 ms 6380 KB Output is correct
49 Correct 17 ms 6380 KB Output is correct
50 Correct 83 ms 6380 KB Output is correct
51 Correct 18 ms 6380 KB Output is correct
52 Correct 22 ms 6380 KB Output is correct
53 Correct 82 ms 6380 KB Output is correct
54 Correct 21 ms 6380 KB Output is correct
55 Correct 23 ms 6380 KB Output is correct
56 Correct 97 ms 6380 KB Output is correct
57 Correct 27 ms 6380 KB Output is correct
58 Correct 25 ms 6380 KB Output is correct
59 Correct 118 ms 6380 KB Output is correct
60 Correct 26 ms 6380 KB Output is correct
61 Correct 28 ms 6380 KB Output is correct
62 Correct 151 ms 6380 KB Output is correct
63 Correct 119 ms 6380 KB Output is correct
64 Correct 200 ms 6396 KB Output is correct
65 Correct 190 ms 6396 KB Output is correct
66 Correct 139 ms 6396 KB Output is correct
67 Correct 130 ms 6396 KB Output is correct
68 Correct 53 ms 6396 KB Output is correct
69 Correct 46 ms 6396 KB Output is correct
70 Correct 44 ms 6396 KB Output is correct
71 Correct 34 ms 6396 KB Output is correct
72 Correct 35 ms 6396 KB Output is correct
73 Correct 40 ms 6476 KB Output is correct
74 Correct 68 ms 6536 KB Output is correct
75 Correct 64 ms 6536 KB Output is correct
76 Correct 72 ms 6536 KB Output is correct
77 Correct 69 ms 6536 KB Output is correct
78 Correct 80 ms 6536 KB Output is correct
79 Correct 61 ms 6536 KB Output is correct
80 Correct 69 ms 6536 KB Output is correct
81 Correct 74 ms 6536 KB Output is correct
82 Correct 68 ms 6536 KB Output is correct
83 Correct 91 ms 6536 KB Output is correct
84 Correct 72 ms 6536 KB Output is correct
85 Correct 75 ms 6536 KB Output is correct
86 Correct 84 ms 6536 KB Output is correct
87 Correct 85 ms 6536 KB Output is correct
88 Correct 90 ms 6536 KB Output is correct
89 Correct 99 ms 6536 KB Output is correct
90 Correct 101 ms 6536 KB Output is correct
91 Correct 96 ms 6536 KB Output is correct
92 Correct 103 ms 6536 KB Output is correct