Submission #104311

# Submission time Handle Problem Language Result Execution time Memory
104311 2019-04-05T03:47:38 Z Badral Mecho (IOI09_mecho) C++17
4 / 100
116 ms 7808 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++) {
		char cc = getchar();
        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;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:50:8: warning: unused variable 'cc' [-Wunused-variable]
   char cc = getchar();
        ^~
# Verdict Execution time Memory Grader output
1 Incorrect 2 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 3 ms 384 KB Output isn't correct
5 Incorrect 2 ms 512 KB Output isn't correct
6 Incorrect 2 ms 384 KB Output isn't correct
7 Incorrect 43 ms 7664 KB Output isn't correct
8 Correct 2 ms 512 KB Output is correct
9 Incorrect 2 ms 512 KB Output isn't correct
10 Incorrect 4 ms 640 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 4 ms 896 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 2 ms 512 KB Output isn't correct
17 Incorrect 3 ms 560 KB Output isn't correct
18 Incorrect 3 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 4 ms 768 KB Output isn't correct
22 Incorrect 3 ms 768 KB Output isn't correct
23 Incorrect 5 ms 896 KB Output isn't correct
24 Incorrect 4 ms 896 KB Output isn't correct
25 Incorrect 4 ms 896 KB Output isn't correct
26 Incorrect 4 ms 896 KB Output isn't correct
27 Incorrect 5 ms 1024 KB Output isn't correct
28 Incorrect 5 ms 896 KB Output isn't correct
29 Incorrect 6 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 7 ms 1024 KB Output isn't correct
33 Incorrect 10 ms 3584 KB Output isn't correct
34 Incorrect 10 ms 3456 KB Output isn't correct
35 Incorrect 12 ms 3584 KB Output isn't correct
36 Incorrect 12 ms 3968 KB Output isn't correct
37 Incorrect 12 ms 4096 KB Output isn't correct
38 Incorrect 13 ms 3940 KB Output isn't correct
39 Incorrect 15 ms 4352 KB Output isn't correct
40 Incorrect 11 ms 4352 KB Output isn't correct
41 Incorrect 14 ms 4480 KB Output isn't correct
42 Incorrect 17 ms 4864 KB Output isn't correct
43 Incorrect 19 ms 4864 KB Output isn't correct
44 Incorrect 17 ms 4864 KB Output isn't correct
45 Incorrect 17 ms 5248 KB Output isn't correct
46 Incorrect 17 ms 5248 KB Output isn't correct
47 Incorrect 16 ms 5248 KB Output isn't correct
48 Incorrect 22 ms 5760 KB Output isn't correct
49 Incorrect 57 ms 5760 KB Output isn't correct
50 Incorrect 21 ms 5820 KB Output isn't correct
51 Incorrect 18 ms 6144 KB Output isn't correct
52 Incorrect 24 ms 6144 KB Output isn't correct
53 Incorrect 22 ms 6144 KB Output isn't correct
54 Incorrect 20 ms 6656 KB Output isn't correct
55 Incorrect 110 ms 6776 KB Output isn't correct
56 Incorrect 24 ms 6648 KB Output isn't correct
57 Incorrect 26 ms 7088 KB Output isn't correct
58 Incorrect 22 ms 7064 KB Output isn't correct
59 Incorrect 23 ms 7040 KB Output isn't correct
60 Incorrect 22 ms 7552 KB Output isn't correct
61 Incorrect 29 ms 7552 KB Output isn't correct
62 Incorrect 31 ms 7680 KB Output isn't correct
63 Incorrect 58 ms 7552 KB Output isn't correct
64 Incorrect 116 ms 7552 KB Output isn't correct
65 Incorrect 28 ms 7544 KB Output isn't correct
66 Incorrect 82 ms 7552 KB Output isn't correct
67 Correct 38 ms 7552 KB Output is correct
68 Incorrect 46 ms 7544 KB Output isn't correct
69 Incorrect 47 ms 7604 KB Output isn't correct
70 Incorrect 42 ms 7544 KB Output isn't correct
71 Incorrect 45 ms 7544 KB Output isn't correct
72 Correct 40 ms 7544 KB Output is correct
73 Incorrect 36 ms 7804 KB Output isn't correct
74 Incorrect 34 ms 7808 KB Output isn't correct
75 Incorrect 36 ms 7772 KB Output isn't correct
76 Incorrect 43 ms 7800 KB Output isn't correct
77 Incorrect 37 ms 7800 KB Output isn't correct
78 Correct 44 ms 7800 KB Output is correct
79 Incorrect 51 ms 7716 KB Output isn't correct
80 Incorrect 44 ms 7672 KB Output isn't correct
81 Incorrect 57 ms 7680 KB Output isn't correct
82 Incorrect 47 ms 7808 KB Output isn't correct
83 Incorrect 44 ms 7672 KB Output isn't correct
84 Incorrect 35 ms 7800 KB Output isn't correct
85 Incorrect 37 ms 7680 KB Output isn't correct
86 Incorrect 37 ms 7672 KB Output isn't correct
87 Incorrect 36 ms 7716 KB Output isn't correct
88 Incorrect 36 ms 7672 KB Output isn't correct
89 Incorrect 42 ms 7552 KB Output isn't correct
90 Incorrect 40 ms 7644 KB Output isn't correct
91 Incorrect 46 ms 7672 KB Output isn't correct
92 Incorrect 41 ms 7672 KB Output isn't correct