Submission #53459

# Submission time Handle Problem Language Result Execution time Memory
53459 2018-06-30T05:16:23 Z 김세빈(#1419) Mecho (IOI09_mecho) C++11
84 / 100
273 ms 9364 KB
#include <bits/stdc++.h>

using namespace std;

char str[808][808];
int D[808][808], P[808][808], Q[1010101];
bool chk[808][808];
int n,k,x,y,z,w,f,r;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main()
{
	int i,j,p,q,a,b,s,e;
	
	scanf("%d%d", &n, &k);
	
	for(i=0;i<n;i++){
		scanf("%s", str[i]);
		
		for(j=0;j<n;j++){
			D[i][j] = 1e9;
			if(str[i][j] == 'H'){
				D[i][j] = 0;
				chk[i][j] = 1;
				Q[++f] = i*n+j;
			}
			else if(str[i][j] == 'M') x = i, y = j;
			else if(str[i][j] == 'D') z = i, w = j;
		}
	}
	
	for(;r<f;){
		p = Q[++r] / n, q = Q[r] % n;
		
		for(i=0;i<4;i++){
			a = p + dx[i], b = q + dy[i];
			if(0 <= a && a < n && 0 <= b && b < n && !chk[a][b] && (str[a][b] == 'G' || str[a][b] == 'M')){
				chk[a][b] = 1;
				D[a][b] = D[p][q] + k;
				Q[++f] = a*n+b;
			}
		}
	}
	
	for(s=0,e=n*n;s<=e;){
		P[x][y] = (s+e>>1) * k;
		
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				chk[i][j] = 0;
			}
		}
		
		f = r = 0;
		Q[++f] = x*n+y;
		
		for(;r<f;){
			p = Q[++r] / n, q = Q[r] % n;
			
			for(i=0;i<4;i++){
				a = p + dx[i], b = q + dy[i];
				if(0 <= a && a < n && 0 <= b && b < n && D[a][b] > P[p][q] + 1 && !chk[a][b] && (str[a][b] == 'G' || str[a][b] == 'D')){
					chk[a][b] = 1;
					P[a][b] = P[p][q] + 1;
					Q[++f] = a*n+b;
				}
			}
		}
		
		if(chk[z][w]) s = (s+e>>1) + 1;
		else e = (s+e>>1) - 1;
	}
	
	printf("%d\n", s-1);
	
	return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:46:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   P[x][y] = (s+e>>1) * k;
              ~^~
mecho.cpp:70:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   if(chk[z][w]) s = (s+e>>1) + 1;
                      ~^~
mecho.cpp:71:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   else e = (s+e>>1) - 1;
             ~^~
mecho.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~
mecho.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", str[i]);
   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 392 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 680 KB Output is correct
6 Correct 2 ms 680 KB Output is correct
7 Correct 110 ms 8420 KB Output is correct
8 Correct 2 ms 8420 KB Output is correct
9 Correct 2 ms 8420 KB Output is correct
10 Correct 2 ms 8420 KB Output is correct
11 Correct 2 ms 8420 KB Output is correct
12 Incorrect 2 ms 8420 KB Output isn't correct
13 Incorrect 2 ms 8420 KB Output isn't correct
14 Correct 2 ms 8420 KB Output is correct
15 Correct 2 ms 8420 KB Output is correct
16 Correct 2 ms 8420 KB Output is correct
17 Correct 2 ms 8420 KB Output is correct
18 Correct 2 ms 8420 KB Output is correct
19 Correct 2 ms 8420 KB Output is correct
20 Correct 2 ms 8420 KB Output is correct
21 Correct 2 ms 8420 KB Output is correct
22 Correct 2 ms 8420 KB Output is correct
23 Correct 2 ms 8420 KB Output is correct
24 Correct 2 ms 8420 KB Output is correct
25 Correct 2 ms 8420 KB Output is correct
26 Correct 2 ms 8420 KB Output is correct
27 Correct 2 ms 8420 KB Output is correct
28 Correct 2 ms 8420 KB Output is correct
29 Correct 3 ms 8420 KB Output is correct
30 Correct 2 ms 8420 KB Output is correct
31 Correct 2 ms 8420 KB Output is correct
32 Correct 2 ms 8420 KB Output is correct
33 Correct 8 ms 8420 KB Output is correct
34 Correct 8 ms 8420 KB Output is correct
35 Correct 27 ms 8420 KB Output is correct
36 Correct 9 ms 8420 KB Output is correct
37 Correct 10 ms 8420 KB Output is correct
38 Correct 36 ms 8420 KB Output is correct
39 Correct 11 ms 8420 KB Output is correct
40 Correct 12 ms 8420 KB Output is correct
41 Correct 48 ms 8420 KB Output is correct
42 Correct 13 ms 8420 KB Output is correct
43 Correct 15 ms 8420 KB Output is correct
44 Correct 67 ms 8420 KB Output is correct
45 Correct 16 ms 8420 KB Output is correct
46 Correct 17 ms 8420 KB Output is correct
47 Correct 69 ms 8420 KB Output is correct
48 Correct 17 ms 8420 KB Output is correct
49 Correct 20 ms 8420 KB Output is correct
50 Correct 83 ms 8420 KB Output is correct
51 Correct 20 ms 8420 KB Output is correct
52 Correct 23 ms 8420 KB Output is correct
53 Correct 137 ms 8420 KB Output is correct
54 Correct 26 ms 8420 KB Output is correct
55 Correct 26 ms 8420 KB Output is correct
56 Correct 163 ms 8420 KB Output is correct
57 Correct 29 ms 8420 KB Output is correct
58 Correct 30 ms 8420 KB Output is correct
59 Correct 198 ms 8420 KB Output is correct
60 Correct 35 ms 8420 KB Output is correct
61 Correct 33 ms 8420 KB Output is correct
62 Correct 199 ms 8828 KB Output is correct
63 Correct 135 ms 8828 KB Output is correct
64 Correct 273 ms 8828 KB Output is correct
65 Correct 199 ms 8828 KB Output is correct
66 Correct 158 ms 8828 KB Output is correct
67 Correct 151 ms 8828 KB Output is correct
68 Correct 64 ms 8828 KB Output is correct
69 Correct 67 ms 8828 KB Output is correct
70 Correct 49 ms 8828 KB Output is correct
71 Correct 58 ms 8828 KB Output is correct
72 Incorrect 41 ms 8828 KB Output isn't correct
73 Incorrect 54 ms 9340 KB Output isn't correct
74 Correct 78 ms 9340 KB Output is correct
75 Correct 108 ms 9340 KB Output is correct
76 Correct 76 ms 9340 KB Output is correct
77 Correct 75 ms 9364 KB Output is correct
78 Correct 94 ms 9364 KB Output is correct
79 Correct 66 ms 9364 KB Output is correct
80 Correct 87 ms 9364 KB Output is correct
81 Correct 82 ms 9364 KB Output is correct
82 Correct 75 ms 9364 KB Output is correct
83 Correct 131 ms 9364 KB Output is correct
84 Correct 91 ms 9364 KB Output is correct
85 Correct 94 ms 9364 KB Output is correct
86 Correct 93 ms 9364 KB Output is correct
87 Correct 116 ms 9364 KB Output is correct
88 Correct 127 ms 9364 KB Output is correct
89 Correct 144 ms 9364 KB Output is correct
90 Correct 102 ms 9364 KB Output is correct
91 Correct 124 ms 9364 KB Output is correct
92 Correct 112 ms 9364 KB Output is correct