Submission #53473

# Submission time Handle Problem Language Result Execution time Memory
53473 2018-06-30T05:38:09 Z 시제연(#2016) Mecho (IOI09_mecho) C++11
84 / 100
250 ms 6672 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 = n * n;
    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 376 KB Output is correct
2 Correct 2 ms 556 KB Output is correct
3 Correct 2 ms 556 KB Output is correct
4 Correct 2 ms 556 KB Output is correct
5 Correct 2 ms 556 KB Output is correct
6 Correct 2 ms 556 KB Output is correct
7 Correct 99 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 2 ms 6380 KB Output is correct
12 Incorrect 3 ms 6380 KB Output isn't correct
13 Incorrect 3 ms 6380 KB Output isn't correct
14 Correct 3 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 3 ms 6380 KB Output is correct
18 Correct 2 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 2 ms 6380 KB Output is correct
22 Correct 3 ms 6380 KB Output is correct
23 Correct 3 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 3 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 2 ms 6380 KB Output is correct
30 Correct 4 ms 6380 KB Output is correct
31 Correct 3 ms 6380 KB Output is correct
32 Correct 3 ms 6380 KB Output is correct
33 Correct 9 ms 6380 KB Output is correct
34 Correct 9 ms 6380 KB Output is correct
35 Correct 27 ms 6380 KB Output is correct
36 Correct 10 ms 6380 KB Output is correct
37 Correct 15 ms 6380 KB Output is correct
38 Correct 35 ms 6380 KB Output is correct
39 Correct 14 ms 6380 KB Output is correct
40 Correct 16 ms 6380 KB Output is correct
41 Correct 77 ms 6380 KB Output is correct
42 Correct 15 ms 6380 KB Output is correct
43 Correct 15 ms 6380 KB Output is correct
44 Correct 73 ms 6380 KB Output is correct
45 Correct 14 ms 6380 KB Output is correct
46 Correct 15 ms 6380 KB Output is correct
47 Correct 80 ms 6380 KB Output is correct
48 Correct 17 ms 6380 KB Output is correct
49 Correct 18 ms 6380 KB Output is correct
50 Correct 91 ms 6380 KB Output is correct
51 Correct 29 ms 6380 KB Output is correct
52 Correct 20 ms 6380 KB Output is correct
53 Correct 112 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 136 ms 6380 KB Output is correct
57 Correct 28 ms 6380 KB Output is correct
58 Correct 28 ms 6380 KB Output is correct
59 Correct 181 ms 6380 KB Output is correct
60 Correct 32 ms 6380 KB Output is correct
61 Correct 33 ms 6380 KB Output is correct
62 Correct 212 ms 6380 KB Output is correct
63 Correct 139 ms 6380 KB Output is correct
64 Correct 250 ms 6396 KB Output is correct
65 Correct 191 ms 6396 KB Output is correct
66 Correct 149 ms 6396 KB Output is correct
67 Correct 143 ms 6396 KB Output is correct
68 Correct 83 ms 6396 KB Output is correct
69 Correct 59 ms 6396 KB Output is correct
70 Correct 66 ms 6396 KB Output is correct
71 Correct 51 ms 6396 KB Output is correct
72 Incorrect 37 ms 6396 KB Output isn't correct
73 Incorrect 51 ms 6524 KB Output isn't correct
74 Correct 67 ms 6524 KB Output is correct
75 Correct 116 ms 6524 KB Output is correct
76 Correct 85 ms 6584 KB Output is correct
77 Correct 72 ms 6672 KB Output is correct
78 Correct 101 ms 6672 KB Output is correct
79 Correct 79 ms 6672 KB Output is correct
80 Correct 75 ms 6672 KB Output is correct
81 Correct 84 ms 6672 KB Output is correct
82 Correct 85 ms 6672 KB Output is correct
83 Correct 143 ms 6672 KB Output is correct
84 Correct 121 ms 6672 KB Output is correct
85 Correct 155 ms 6672 KB Output is correct
86 Correct 118 ms 6672 KB Output is correct
87 Correct 101 ms 6672 KB Output is correct
88 Correct 116 ms 6672 KB Output is correct
89 Correct 116 ms 6672 KB Output is correct
90 Correct 117 ms 6672 KB Output is correct
91 Correct 166 ms 6672 KB Output is correct
92 Correct 130 ms 6672 KB Output is correct