답안 #103670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
103670 2019-04-02T03:53:38 Z tugushka Mecho (IOI09_mecho) C++14
4 / 100
3 ms 512 KB
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;

using pii = pair < int, int >;
const int N = 1005;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};

char a[N][N];
pii mecho, home;
int n, s, hive[N][N];

void hive_bfs(){
	memset( hive, 11, sizeof(hive) );
	queue < pii > q;
	for(int i = 0 ; i < n ; i++) for(int j = 0 ; j < n ; j++){
		if( a[i][j] == 'H' ){
			q.push( mp( i, j ) );
			hive[i][j] = 0;
		}
	}

	int dis = 0;
	while( !q.empty() ){
		dis += s;
		int sz = q.size();
		while( sz-- ){
			int x, y;
			tie(x, y) = q.front();
			q.pop();
			for(int i = 0 ; i < 4 ; i++){
				int tx = x+dx[i], ty = y+dy[i];
				if( tx < 0 || ty < 0 || tx >= n || ty >= n ) continue;
				if( a[tx][ty] == 'G' && hive[tx][ty] > 2e6 ){
					hive[tx][ty] = dis;
					q.push( mp( tx, ty ) );
				}
			}
		}
	}

	/*
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < n ; j++){
			if( hive[i][j] > 2e6 ) printf("@@ ");
			else printf("%2d ", hive[i][j]);
		}
		printf("\n");
	}
	*/
}

bool mecho_bfs(int start_time){
	bool used[N][N];
	memset( used, 0, sizeof(used) );

	queue < pii > q;
	q.push( mecho );

	int dis = start_time;
	while( !q.empty() ){
		dis++;
		// cout << "dis " << dis << " : ";

		int sz = q.size();
		while( sz-- ){
			int x, y;
			tie(x, y) = q.front();
			q.pop();
			for(int i = 0 ; i < 4 ; i++){
				int tx = x+dx[i], ty = y+dy[i];
				if( tx < 0 || ty < 0 || tx >= n || ty >= n ) continue;
				if( !used[tx][ty] && a[tx][ty] == 'G' && hive[tx][ty] > dis ){
					used[tx][ty] = 1;
					// cout << "( " << tx << ',' << ty << " ), ";
					q.push( mp( tx, ty ) );
				}
			}
		}
		// cout << endl;
	}

	return used[ home.first ][ home.second ];
}

int main(){
	cout << "-1\n";
	return 0;
	scanf("%d %d", &n, &s);
	for(int i = 0 ; i < n ; i++){
		scanf("%s", a[i]);
	}
	hive_bfs();
	for(int i = 0 ; i < n ; i++) for(int j = 0 ; j < n ; j++){
		if( a[i][j] == 'D' ){
			home = mp( i, j );
			a[i][j] = 'G';
		}
		if( a[i][j] == 'G' ){
			mecho = mp( i, j );
		}
	}

	if( !mecho_bfs( 0 ) ){
		printf("-1\n");
		return 0;
	}

	int res = 0;
	while( mecho_bfs( s*(res+1) ) ) res++;
	cout << res << endl;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:90:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &s);
  ~~~~~^~~~~~~~~~~~~~~~~
mecho.cpp:92:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", a[i]);
   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Incorrect 2 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 2 ms 384 KB Output isn't correct
7 Incorrect 3 ms 384 KB Output isn't correct
8 Correct 2 ms 256 KB Output is correct
9 Incorrect 2 ms 384 KB Output isn't correct
10 Incorrect 2 ms 384 KB Output isn't correct
11 Incorrect 2 ms 256 KB Output isn't correct
12 Incorrect 2 ms 384 KB Output isn't correct
13 Incorrect 2 ms 256 KB Output isn't correct
14 Correct 2 ms 384 KB Output is correct
15 Incorrect 2 ms 384 KB Output isn't correct
16 Incorrect 2 ms 256 KB Output isn't correct
17 Incorrect 2 ms 384 KB Output isn't correct
18 Incorrect 2 ms 256 KB Output isn't correct
19 Incorrect 2 ms 256 KB Output isn't correct
20 Incorrect 2 ms 384 KB Output isn't correct
21 Incorrect 3 ms 384 KB Output isn't correct
22 Incorrect 2 ms 256 KB Output isn't correct
23 Incorrect 2 ms 384 KB Output isn't correct
24 Incorrect 2 ms 256 KB Output isn't correct
25 Incorrect 2 ms 256 KB Output isn't correct
26 Incorrect 2 ms 384 KB Output isn't correct
27 Incorrect 2 ms 384 KB Output isn't correct
28 Incorrect 2 ms 384 KB Output isn't correct
29 Incorrect 2 ms 384 KB Output isn't correct
30 Incorrect 2 ms 384 KB Output isn't correct
31 Incorrect 3 ms 384 KB Output isn't correct
32 Incorrect 2 ms 256 KB Output isn't correct
33 Incorrect 3 ms 356 KB Output isn't correct
34 Incorrect 2 ms 384 KB Output isn't correct
35 Incorrect 2 ms 256 KB Output isn't correct
36 Incorrect 2 ms 256 KB Output isn't correct
37 Incorrect 2 ms 256 KB Output isn't correct
38 Incorrect 3 ms 256 KB Output isn't correct
39 Incorrect 2 ms 384 KB Output isn't correct
40 Incorrect 2 ms 384 KB Output isn't correct
41 Incorrect 2 ms 512 KB Output isn't correct
42 Incorrect 2 ms 384 KB Output isn't correct
43 Incorrect 2 ms 256 KB Output isn't correct
44 Incorrect 2 ms 256 KB Output isn't correct
45 Incorrect 2 ms 384 KB Output isn't correct
46 Incorrect 2 ms 256 KB Output isn't correct
47 Incorrect 2 ms 384 KB Output isn't correct
48 Incorrect 2 ms 384 KB Output isn't correct
49 Incorrect 2 ms 384 KB Output isn't correct
50 Incorrect 3 ms 384 KB Output isn't correct
51 Incorrect 2 ms 384 KB Output isn't correct
52 Incorrect 2 ms 256 KB Output isn't correct
53 Incorrect 2 ms 256 KB Output isn't correct
54 Incorrect 2 ms 384 KB Output isn't correct
55 Incorrect 2 ms 384 KB Output isn't correct
56 Incorrect 2 ms 384 KB Output isn't correct
57 Incorrect 2 ms 384 KB Output isn't correct
58 Incorrect 2 ms 384 KB Output isn't correct
59 Incorrect 2 ms 384 KB Output isn't correct
60 Incorrect 3 ms 384 KB Output isn't correct
61 Incorrect 2 ms 256 KB Output isn't correct
62 Incorrect 2 ms 256 KB Output isn't correct
63 Incorrect 2 ms 384 KB Output isn't correct
64 Incorrect 2 ms 256 KB Output isn't correct
65 Incorrect 2 ms 384 KB Output isn't correct
66 Incorrect 2 ms 384 KB Output isn't correct
67 Correct 2 ms 384 KB Output is correct
68 Incorrect 2 ms 256 KB Output isn't correct
69 Incorrect 2 ms 256 KB Output isn't correct
70 Incorrect 2 ms 256 KB Output isn't correct
71 Incorrect 2 ms 384 KB Output isn't correct
72 Incorrect 2 ms 384 KB Output isn't correct
73 Incorrect 2 ms 384 KB Output isn't correct
74 Incorrect 3 ms 384 KB Output isn't correct
75 Incorrect 2 ms 256 KB Output isn't correct
76 Incorrect 2 ms 256 KB Output isn't correct
77 Incorrect 2 ms 256 KB Output isn't correct
78 Correct 2 ms 256 KB Output is correct
79 Incorrect 2 ms 384 KB Output isn't correct
80 Incorrect 2 ms 384 KB Output isn't correct
81 Incorrect 2 ms 384 KB Output isn't correct
82 Incorrect 2 ms 384 KB Output isn't correct
83 Incorrect 2 ms 384 KB Output isn't correct
84 Incorrect 2 ms 256 KB Output isn't correct
85 Incorrect 2 ms 384 KB Output isn't correct
86 Incorrect 2 ms 384 KB Output isn't correct
87 Incorrect 2 ms 256 KB Output isn't correct
88 Incorrect 2 ms 256 KB Output isn't correct
89 Incorrect 2 ms 256 KB Output isn't correct
90 Incorrect 2 ms 384 KB Output isn't correct
91 Incorrect 2 ms 256 KB Output isn't correct
92 Incorrect 2 ms 384 KB Output isn't correct