Submission #53466

# Submission time Handle Problem Language Result Execution time Memory
53466 2018-06-30T05:30:43 Z 김세빈(#1419) Mecho (IOI09_mecho) C++11
56 / 100
257 ms 9664 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;){
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				chk[i][j] = 0;
			}
		}
		
		f = r = 0;
		P[x][y] = (s+e>>1) * k;
		if(D[x][y] > P[a][b]){
			chk[x][y] = 1;
			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:53:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   P[x][y] = (s+e>>1) * k;
              ~^~
mecho.cpp:72:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   if(chk[z][w]) s = (s+e>>1) + 1;
                      ~^~
mecho.cpp:73: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]);
   ~~~~~^~~~~~~~~~~~~~
mecho.cpp:54:22: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if(D[x][y] > P[a][b]){
                ~~~~~~^
mecho.cpp:54:22: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 612 KB Output is correct
6 Correct 2 ms 664 KB Output is correct
7 Correct 110 ms 8520 KB Output is correct
8 Correct 2 ms 8520 KB Output is correct
9 Correct 2 ms 8520 KB Output is correct
10 Correct 2 ms 8520 KB Output is correct
11 Correct 2 ms 8520 KB Output is correct
12 Incorrect 2 ms 8520 KB Output isn't correct
13 Incorrect 2 ms 8520 KB Output isn't correct
14 Correct 2 ms 8520 KB Output is correct
15 Incorrect 2 ms 8520 KB Output isn't correct
16 Correct 2 ms 8520 KB Output is correct
17 Incorrect 2 ms 8520 KB Output isn't correct
18 Correct 2 ms 8520 KB Output is correct
19 Incorrect 2 ms 8520 KB Output isn't correct
20 Correct 2 ms 8520 KB Output is correct
21 Incorrect 3 ms 8520 KB Output isn't correct
22 Correct 2 ms 8520 KB Output is correct
23 Incorrect 2 ms 8520 KB Output isn't correct
24 Correct 2 ms 8520 KB Output is correct
25 Incorrect 3 ms 8520 KB Output isn't correct
26 Correct 2 ms 8520 KB Output is correct
27 Incorrect 2 ms 8520 KB Output isn't correct
28 Correct 3 ms 8520 KB Output is correct
29 Incorrect 3 ms 8520 KB Output isn't correct
30 Correct 2 ms 8520 KB Output is correct
31 Incorrect 3 ms 8520 KB Output isn't correct
32 Correct 3 ms 8520 KB Output is correct
33 Incorrect 8 ms 8520 KB Output isn't correct
34 Incorrect 8 ms 8520 KB Output isn't correct
35 Correct 27 ms 8520 KB Output is correct
36 Incorrect 9 ms 8520 KB Output isn't correct
37 Correct 11 ms 8520 KB Output is correct
38 Correct 36 ms 8520 KB Output is correct
39 Incorrect 11 ms 8520 KB Output isn't correct
40 Correct 13 ms 8520 KB Output is correct
41 Correct 49 ms 8520 KB Output is correct
42 Incorrect 13 ms 8520 KB Output isn't correct
43 Correct 15 ms 8520 KB Output is correct
44 Correct 64 ms 8520 KB Output is correct
45 Incorrect 16 ms 8520 KB Output isn't correct
46 Correct 17 ms 8520 KB Output is correct
47 Correct 80 ms 8520 KB Output is correct
48 Incorrect 17 ms 8520 KB Output isn't correct
49 Incorrect 22 ms 8520 KB Output isn't correct
50 Correct 108 ms 8520 KB Output is correct
51 Incorrect 22 ms 8520 KB Output isn't correct
52 Correct 23 ms 8520 KB Output is correct
53 Correct 110 ms 8520 KB Output is correct
54 Incorrect 25 ms 8520 KB Output isn't correct
55 Correct 26 ms 8520 KB Output is correct
56 Correct 151 ms 8520 KB Output is correct
57 Incorrect 26 ms 8520 KB Output isn't correct
58 Correct 37 ms 8520 KB Output is correct
59 Correct 169 ms 8520 KB Output is correct
60 Incorrect 28 ms 8520 KB Output isn't correct
61 Correct 34 ms 8520 KB Output is correct
62 Correct 178 ms 8956 KB Output is correct
63 Correct 135 ms 8956 KB Output is correct
64 Correct 257 ms 8956 KB Output is correct
65 Correct 194 ms 8956 KB Output is correct
66 Correct 163 ms 8956 KB Output is correct
67 Correct 150 ms 8956 KB Output is correct
68 Correct 64 ms 8956 KB Output is correct
69 Correct 64 ms 8956 KB Output is correct
70 Correct 49 ms 8956 KB Output is correct
71 Correct 56 ms 8956 KB Output is correct
72 Incorrect 42 ms 8956 KB Output isn't correct
73 Correct 44 ms 9340 KB Output is correct
74 Correct 72 ms 9468 KB Output is correct
75 Correct 93 ms 9664 KB Output is correct
76 Correct 80 ms 9664 KB Output is correct
77 Correct 78 ms 9664 KB Output is correct
78 Correct 99 ms 9664 KB Output is correct
79 Correct 63 ms 9664 KB Output is correct
80 Correct 77 ms 9664 KB Output is correct
81 Correct 85 ms 9664 KB Output is correct
82 Correct 80 ms 9664 KB Output is correct
83 Correct 99 ms 9664 KB Output is correct
84 Correct 88 ms 9664 KB Output is correct
85 Correct 97 ms 9664 KB Output is correct
86 Correct 96 ms 9664 KB Output is correct
87 Correct 92 ms 9664 KB Output is correct
88 Correct 102 ms 9664 KB Output is correct
89 Correct 100 ms 9664 KB Output is correct
90 Correct 107 ms 9664 KB Output is correct
91 Correct 104 ms 9664 KB Output is correct
92 Correct 110 ms 9664 KB Output is correct