Submission #74663

# Submission time Handle Problem Language Result Execution time Memory
74663 2018-09-06T00:17:54 Z arman_ferdous Mecho (IOI09_mecho) C++17
6 / 100
688 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};

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;

	queue<ii> q; 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};
		}

	queue<ii> q;
	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:41: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:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %s", s[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Incorrect 3 ms 456 KB Output isn't correct
4 Incorrect 2 ms 532 KB Output isn't correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 564 KB Output is correct
7 Runtime error 311 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 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.
13 Runtime error 688 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 606 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 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.
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 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.
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 19 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 30 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 332 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 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.
37 Runtime error 40 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 300 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Runtime error 27 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 44 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 289 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
42 Runtime error 33 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 59 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 301 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
45 Runtime error 43 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 303 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
48 Runtime error 45 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 70 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 277 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
51 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.
52 Runtime error 82 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 281 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
54 Runtime error 64 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 108 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 73 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 111 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 286 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
60 Runtime error 78 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 122 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 283 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
63 Runtime error 126 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 186 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 200 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 159 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 140 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 58 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 50 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 47 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 45 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 37 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 532 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
74 Runtime error 533 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
75 Runtime error 514 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
76 Runtime error 516 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
77 Runtime error 528 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
78 Runtime error 440 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
79 Runtime error 448 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
80 Runtime error 434 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
81 Runtime error 463 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
82 Runtime error 458 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
83 Runtime error 389 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
84 Runtime error 385 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
85 Runtime error 394 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
86 Runtime error 387 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
87 Runtime error 394 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
88 Runtime error 339 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
89 Runtime error 351 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
90 Runtime error 351 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
91 Runtime error 336 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
92 Runtime error 339 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)