Submission #104308

# Submission time Handle Problem Language Result Execution time Memory
104308 2019-04-05T03:41:21 Z Badral Mecho (IOI09_mecho) C++17
4 / 100
157 ms 7928 KB
#include<bits/stdc++.h>

using namespace std;

#define pi pair<int, int>
 
char a[1015][1015];
int dx[] = {0, 0, 0, 1, -1, -1, 1, 1, -1};
int dy[] = {0, 1, -1, 0, 0, -1, -1, 1, 1};
int bear[1105][1015], bee[1105][1015], xx = -1, yy = -1, xxx = -1, yyy = -1, n, kk;
 
bool asdasd = 0;
 
bool can(int k) {
 
    if ( k >= bee[xx][yy] ) return 0;
 
    for ( int i = 1; i <= n; i++ ) 
        for ( int j = 1; j <= n; j++ ) 
            bear[i][j] = INT_MAX;
 
    bear[xx][yy] = 0;
 
    queue < pi > q;
    
    q.push(make_pair(xx, yy));
        int x, y;    
    while(!q.empty()) {
        tie(x, y) = q.front();
        q.pop();
        for(int i = 1; i <= 4; i++) {
            int x1 = x + dx[i], y1 = y + dy[i];
            if ( a[x1][y1] == 'D' ) {asdasd = 1; return 1;}
            if ( a[x1][y1] == 'G' && bear[x][y] + 1 < kk * ( bee[x1][y1] - k ) && bear[x1][y1] == INT_MAX ) {
                bear[x1][y1] = bear[x][y] + 1;
                q.push ( make_pair ( x1, y1 ) ); 
            }
        }
    }
    return 0;  
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> kk;
    queue < pi > p;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            bee[i][j] = INT_MAX; 
            a[i][j] = getchar();
            if ( a[i][j] == 'H' ) {p.push(make_pair(i, j)); bee[i][j] = 0;}
            if ( a[i][j] == 'M' ) xx = i, yy = j;
        }
    }
 
    while(!p.empty()) {
        int x, y; tie(x, y) = p.front(); p.pop();
        for ( int i = 1; i <= 4; i++ ) {
            int x1 = x + dx[i], y1 = y + dy[i];
            if ( bee[x1][y1] == INT_MAX && ( a[x1][y1] == 'G' || a[x1][y1] == 'M' ) ) {
                bee[x1][y1] = bee[x][y] + 1; p.push ( make_pair ( x1, y1 ) );
            }
        }
    }
 
    int k = 0, mm = n * n ;
    
	for(int i = mm/2; i >= 1; i /= 2) 
        while(i + k <= mm && can(i+k)) 
            k += i;
	
    if ( !can(0) ) cout << -1;
    else cout << k;
}
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Incorrect 2 ms 384 KB Output isn't correct
4 Incorrect 2 ms 384 KB Output isn't correct
5 Incorrect 3 ms 384 KB Output isn't correct
6 Incorrect 3 ms 384 KB Output isn't correct
7 Incorrect 47 ms 7800 KB Output isn't correct
8 Correct 3 ms 512 KB Output is correct
9 Incorrect 2 ms 512 KB Output isn't correct
10 Incorrect 3 ms 512 KB Output isn't correct
11 Incorrect 2 ms 512 KB Output isn't correct
12 Incorrect 4 ms 896 KB Output isn't correct
13 Incorrect 5 ms 768 KB Output isn't correct
14 Correct 4 ms 896 KB Output is correct
15 Incorrect 2 ms 512 KB Output isn't correct
16 Incorrect 3 ms 640 KB Output isn't correct
17 Incorrect 3 ms 512 KB Output isn't correct
18 Incorrect 2 ms 512 KB Output isn't correct
19 Incorrect 3 ms 640 KB Output isn't correct
20 Incorrect 3 ms 640 KB Output isn't correct
21 Incorrect 3 ms 768 KB Output isn't correct
22 Incorrect 3 ms 768 KB Output isn't correct
23 Incorrect 4 ms 896 KB Output isn't correct
24 Incorrect 5 ms 896 KB Output isn't correct
25 Incorrect 6 ms 1024 KB Output isn't correct
26 Incorrect 4 ms 896 KB Output isn't correct
27 Incorrect 5 ms 896 KB Output isn't correct
28 Incorrect 4 ms 896 KB Output isn't correct
29 Incorrect 5 ms 1024 KB Output isn't correct
30 Incorrect 5 ms 1024 KB Output isn't correct
31 Incorrect 5 ms 1024 KB Output isn't correct
32 Incorrect 5 ms 1024 KB Output isn't correct
33 Incorrect 10 ms 3456 KB Output isn't correct
34 Incorrect 10 ms 3456 KB Output isn't correct
35 Incorrect 10 ms 3584 KB Output isn't correct
36 Incorrect 11 ms 3968 KB Output isn't correct
37 Incorrect 12 ms 3968 KB Output isn't correct
38 Incorrect 15 ms 3916 KB Output isn't correct
39 Incorrect 11 ms 4352 KB Output isn't correct
40 Incorrect 12 ms 4324 KB Output isn't correct
41 Incorrect 19 ms 4472 KB Output isn't correct
42 Incorrect 13 ms 4780 KB Output isn't correct
43 Incorrect 13 ms 4864 KB Output isn't correct
44 Incorrect 15 ms 4864 KB Output isn't correct
45 Incorrect 21 ms 5248 KB Output isn't correct
46 Incorrect 15 ms 5248 KB Output isn't correct
47 Incorrect 16 ms 5248 KB Output isn't correct
48 Incorrect 16 ms 5760 KB Output isn't correct
49 Incorrect 18 ms 5760 KB Output isn't correct
50 Incorrect 17 ms 5760 KB Output isn't correct
51 Incorrect 20 ms 6144 KB Output isn't correct
52 Incorrect 20 ms 6144 KB Output isn't correct
53 Incorrect 17 ms 6144 KB Output isn't correct
54 Incorrect 23 ms 6628 KB Output isn't correct
55 Incorrect 24 ms 6628 KB Output isn't correct
56 Incorrect 25 ms 6656 KB Output isn't correct
57 Incorrect 32 ms 7168 KB Output isn't correct
58 Incorrect 24 ms 7040 KB Output isn't correct
59 Incorrect 23 ms 7040 KB Output isn't correct
60 Incorrect 25 ms 7552 KB Output isn't correct
61 Incorrect 26 ms 7552 KB Output isn't correct
62 Incorrect 32 ms 7456 KB Output isn't correct
63 Incorrect 38 ms 7544 KB Output isn't correct
64 Incorrect 43 ms 7672 KB Output isn't correct
65 Incorrect 39 ms 7544 KB Output isn't correct
66 Incorrect 41 ms 7552 KB Output isn't correct
67 Correct 40 ms 7552 KB Output is correct
68 Incorrect 50 ms 7544 KB Output isn't correct
69 Incorrect 62 ms 7544 KB Output isn't correct
70 Incorrect 48 ms 7672 KB Output isn't correct
71 Incorrect 48 ms 7544 KB Output isn't correct
72 Incorrect 67 ms 7512 KB Output isn't correct
73 Incorrect 38 ms 7800 KB Output isn't correct
74 Incorrect 36 ms 7800 KB Output isn't correct
75 Incorrect 37 ms 7800 KB Output isn't correct
76 Incorrect 42 ms 7772 KB Output isn't correct
77 Incorrect 41 ms 7800 KB Output isn't correct
78 Correct 77 ms 7720 KB Output is correct
79 Incorrect 157 ms 7680 KB Output isn't correct
80 Incorrect 88 ms 7908 KB Output isn't correct
81 Incorrect 66 ms 7796 KB Output isn't correct
82 Incorrect 75 ms 7928 KB Output isn't correct
83 Incorrect 42 ms 7672 KB Output isn't correct
84 Incorrect 48 ms 7716 KB Output isn't correct
85 Incorrect 49 ms 7800 KB Output isn't correct
86 Incorrect 41 ms 7772 KB Output isn't correct
87 Incorrect 38 ms 7804 KB Output isn't correct
88 Incorrect 48 ms 7672 KB Output isn't correct
89 Incorrect 49 ms 7672 KB Output isn't correct
90 Incorrect 42 ms 7672 KB Output isn't correct
91 Incorrect 44 ms 7672 KB Output isn't correct
92 Incorrect 47 ms 7672 KB Output isn't correct