답안 #74664

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
74664 2018-09-06T00:20:13 Z arman_ferdous Mecho (IOI09_mecho) C++17
6 / 100
682 ms 66560 KB
#include <bits/stdc++.h>
using namespace std;

#define xx first
#define yy second
typedef pair<int,int> ii;
const int N = 888;
const int inf = 2e9;

int n, step, d[N][N], dist[N][N];
char s[N][N];
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

queue<ii> q;
ii mecho, home;

bool can(int t) {
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			dist[i][j] = inf;

	q.push(mecho);
	dist[mecho.xx][mecho.yy] = 0;
	while(!q.empty()) {
		ii u = q.front(); q.pop();
		for(int i = 0; i < 4; i++) {
			ii v = {u.xx + dx[i], u.yy + dy[i]};

			if(min(v.xx,v.yy) < 0 || n <= max(v.xx,v.yy)) continue;
			char cell = s[v.xx][v.yy];
			if(cell == 'T' || cell == 'M' || cell == 'H') continue;
			int arrival = ceil((double)(dist[u.xx][u.yy] + 1.) / step) + t;
			if(arrival > d[v.xx][v.yy] || dist[u.xx][u.yy] + 1 > dist[v.xx][v.yy]) continue;
			dist[v.xx][v.yy] = dist[u.xx][u.yy] + 1;
			q.push(v);
		}
	}
	return dist[home.xx][home.yy] != inf;
}

int main() {
	scanf("%d %d", &n, &step);
	for(int i = 0; i < n; i++)
		scanf(" %s", s[i]);

	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++) {
			d[i][j] = inf;
			if(s[i][j] == 'M') mecho = {i,j};
			else if(s[i][j] == 'D') home = {i,j};
		}

	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++) 
			if(s[i][j] == 'H') {
				q.push({i,j});
				d[i][j] = 0;
			}

	while(!q.empty()) {
		ii u = q.front(); q.pop();
		for(int i = 0; i < 4; i++) {
			ii v = {u.xx + dx[i], u.yy + dy[i]};

			if(min(v.xx,v.yy) < 0 || n <= max(v.xx,v.yy)) continue;
			char cell = s[v.xx][v.yy];
			if(cell == 'T' || cell == 'D' || cell == 'H') continue;
			if(d[v.xx][v.yy] < d[u.xx][u.yy] + 1) continue;
			d[v.xx][v.yy] = d[u.xx][u.yy] + 1;
			q.push(v);
		}
	}
	int lo = 0, hi = n+n, ans = -1;
		while(lo <= hi) {
		int mid = (lo + hi) >> 1;
		if(can(mid)) ans = mid, lo = mid+1;
		else hi = mid-1;
	} printf("%d\n", ans);
	return 0;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &step);
  ~~~~~^~~~~~~~~~~~~~~~~~~~
mecho.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %s", s[i]);
   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Incorrect 2 ms 448 KB Output isn't correct
3 Incorrect 2 ms 448 KB Output isn't correct
4 Incorrect 2 ms 448 KB Output isn't correct
5 Correct 2 ms 572 KB Output is correct
6 Correct 2 ms 648 KB Output is correct
7 Runtime error 322 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
8 Runtime error 2 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
9 Runtime error 2 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
10 Runtime error 2 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
11 Runtime error 2 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
12 Runtime error 3 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
13 Runtime error 682 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 605 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Runtime error 2 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
16 Runtime error 2 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
17 Runtime error 2 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
18 Runtime error 2 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
19 Runtime error 2 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
20 Runtime error 2 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
21 Runtime error 2 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
22 Runtime error 2 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
23 Runtime error 2 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
24 Runtime error 2 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
25 Runtime error 5 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
26 Runtime error 2 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
27 Runtime error 3 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
28 Runtime error 3 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
29 Runtime error 3 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
30 Runtime error 3 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
31 Runtime error 3 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
32 Runtime error 3 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
33 Runtime error 17 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
34 Runtime error 24 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
35 Runtime error 294 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Runtime error 21 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
37 Runtime error 29 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
38 Runtime error 291 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Runtime error 25 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
40 Runtime error 39 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
41 Runtime error 279 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Runtime error 32 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
43 Runtime error 46 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
44 Runtime error 292 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
45 Runtime error 41 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
46 Runtime error 60 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
47 Runtime error 287 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
48 Runtime error 48 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
49 Runtime error 69 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
50 Runtime error 299 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
51 Runtime error 54 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
52 Runtime error 85 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
53 Runtime error 284 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
54 Runtime error 65 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
55 Runtime error 100 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
56 Runtime error 292 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
57 Runtime error 72 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
58 Runtime error 115 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
59 Runtime error 318 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
60 Runtime error 84 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
61 Runtime error 146 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
62 Runtime error 290 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
63 Runtime error 136 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
64 Runtime error 197 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
65 Runtime error 188 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
66 Runtime error 169 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
67 Runtime error 150 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
68 Runtime error 61 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
69 Runtime error 55 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
70 Runtime error 55 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
71 Runtime error 51 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
72 Runtime error 35 ms 66560 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
73 Runtime error 556 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
74 Runtime error 539 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
75 Runtime error 548 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
76 Runtime error 531 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
77 Runtime error 585 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
78 Runtime error 453 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
79 Runtime error 474 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
80 Runtime error 447 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
81 Runtime error 508 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
82 Runtime error 460 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
83 Runtime error 385 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
84 Runtime error 411 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
85 Runtime error 397 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
86 Runtime error 379 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
87 Runtime error 384 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
88 Runtime error 351 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
89 Runtime error 353 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
90 Runtime error 345 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
91 Runtime error 353 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
92 Runtime error 346 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)