Submission #104312

# Submission time Handle Problem Language Result Execution time Memory
104312 2019-04-05T03:49:28 Z Badral Mecho (IOI09_mecho) C++17
4 / 100
131 ms 7876 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;
		char cc = getchar();
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            bee[i][j] = INT_MAX; 
            a[i][j] = getchar();
			// cout<<a[i][j]<<" ";
            if ( a[i][j] == 'H' ) {p.push(make_pair(i, j)); bee[i][j] = 0;}
            if ( a[i][j] == 'M' ) xx = i, yy = j;
        }
		char cc = getchar();
    }
 
    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:58:8: warning: unused variable 'cc' [-Wunused-variable]
   char cc = getchar();
        ^~
mecho.cpp:49: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 3 ms 384 KB Output isn't correct
3 Incorrect 3 ms 384 KB Output isn't correct
4 Incorrect 2 ms 384 KB Output isn't correct
5 Incorrect 2 ms 384 KB Output isn't correct
6 Incorrect 3 ms 512 KB Output isn't correct
7 Incorrect 41 ms 7672 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 4 ms 512 KB Output isn't correct
11 Incorrect 3 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 3 ms 512 KB Output isn't correct
16 Incorrect 3 ms 512 KB Output isn't correct
17 Incorrect 3 ms 640 KB Output isn't correct
18 Incorrect 2 ms 512 KB Output isn't correct
19 Incorrect 2 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 4 ms 768 KB Output isn't correct
24 Incorrect 5 ms 896 KB Output isn't correct
25 Incorrect 5 ms 896 KB Output isn't correct
26 Incorrect 4 ms 896 KB Output isn't correct
27 Incorrect 5 ms 768 KB Output isn't correct
28 Incorrect 5 ms 1024 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 1100 KB Output isn't correct
32 Incorrect 7 ms 1024 KB Output isn't correct
33 Incorrect 10 ms 3456 KB Output isn't correct
34 Incorrect 11 ms 3456 KB Output isn't correct
35 Incorrect 11 ms 3456 KB Output isn't correct
36 Incorrect 11 ms 3968 KB Output isn't correct
37 Incorrect 14 ms 3968 KB Output isn't correct
38 Incorrect 16 ms 3968 KB Output isn't correct
39 Incorrect 12 ms 4352 KB Output isn't correct
40 Incorrect 12 ms 4352 KB Output isn't correct
41 Incorrect 14 ms 4352 KB Output isn't correct
42 Incorrect 12 ms 4864 KB Output isn't correct
43 Incorrect 13 ms 4800 KB Output isn't correct
44 Incorrect 16 ms 4864 KB Output isn't correct
45 Incorrect 16 ms 5248 KB Output isn't correct
46 Incorrect 16 ms 5248 KB Output isn't correct
47 Incorrect 18 ms 5248 KB Output isn't correct
48 Incorrect 19 ms 5760 KB Output isn't correct
49 Incorrect 58 ms 5804 KB Output isn't correct
50 Incorrect 22 ms 5760 KB Output isn't correct
51 Incorrect 17 ms 6144 KB Output isn't correct
52 Incorrect 22 ms 6144 KB Output isn't correct
53 Incorrect 28 ms 6144 KB Output isn't correct
54 Incorrect 20 ms 6656 KB Output isn't correct
55 Incorrect 76 ms 6700 KB Output isn't correct
56 Incorrect 21 ms 6656 KB Output isn't correct
57 Incorrect 25 ms 7164 KB Output isn't correct
58 Incorrect 22 ms 7040 KB Output isn't correct
59 Incorrect 25 ms 7040 KB Output isn't correct
60 Incorrect 23 ms 7456 KB Output isn't correct
61 Incorrect 26 ms 7552 KB Output isn't correct
62 Incorrect 31 ms 7544 KB Output isn't correct
63 Incorrect 54 ms 7544 KB Output isn't correct
64 Incorrect 131 ms 7552 KB Output isn't correct
65 Incorrect 25 ms 7552 KB Output isn't correct
66 Incorrect 72 ms 7544 KB Output isn't correct
67 Correct 38 ms 7544 KB Output is correct
68 Incorrect 52 ms 7672 KB Output isn't correct
69 Incorrect 51 ms 7544 KB Output isn't correct
70 Incorrect 55 ms 7544 KB Output isn't correct
71 Incorrect 43 ms 7540 KB Output isn't correct
72 Correct 55 ms 7544 KB Output is correct
73 Incorrect 35 ms 7800 KB Output isn't correct
74 Incorrect 36 ms 7800 KB Output isn't correct
75 Incorrect 45 ms 7800 KB Output isn't correct
76 Incorrect 38 ms 7800 KB Output isn't correct
77 Incorrect 50 ms 7808 KB Output isn't correct
78 Correct 54 ms 7800 KB Output is correct
79 Incorrect 65 ms 7804 KB Output isn't correct
80 Incorrect 60 ms 7800 KB Output isn't correct
81 Incorrect 54 ms 7800 KB Output isn't correct
82 Incorrect 60 ms 7680 KB Output isn't correct
83 Incorrect 48 ms 7672 KB Output isn't correct
84 Incorrect 49 ms 7672 KB Output isn't correct
85 Incorrect 44 ms 7876 KB Output isn't correct
86 Incorrect 43 ms 7672 KB Output isn't correct
87 Incorrect 43 ms 7716 KB Output isn't correct
88 Incorrect 44 ms 7672 KB Output isn't correct
89 Incorrect 55 ms 7680 KB Output isn't correct
90 Incorrect 40 ms 7672 KB Output isn't correct
91 Incorrect 44 ms 7676 KB Output isn't correct
92 Incorrect 40 ms 7672 KB Output isn't correct