Submission #74666

# Submission time Handle Problem Language Result Execution time Memory
74666 2018-09-06T00:24:50 Z arman_ferdous Mecho (IOI09_mecho) C++17
6 / 100
702 ms 66560 KB
#include <bits/stdc++.h>
using namespace std;

#define xx first
#define yy second
typedef pair<int,int> ii;
const int N = 804;
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]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Incorrect 2 ms 432 KB Output isn't correct
4 Incorrect 2 ms 512 KB Output isn't correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 3 ms 612 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 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.
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 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.
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 702 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 619 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 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.
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 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.
26 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.
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 4 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 23 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 287 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
36 Runtime error 22 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 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.
38 Runtime error 289 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
39 Runtime error 26 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 42 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 296 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 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.
44 Runtime error 289 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 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.
47 Runtime error 299 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
48 Runtime error 53 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 83 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 302 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 90 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 316 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
54 Runtime error 76 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 110 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 309 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 121 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 335 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
60 Runtime error 83 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 143 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 282 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
63 Runtime error 141 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 191 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 211 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 170 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 148 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 75 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 49 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 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.
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 543 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
74 Runtime error 513 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
75 Runtime error 520 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
76 Runtime error 519 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
77 Runtime error 523 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 482 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
80 Runtime error 459 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
81 Runtime error 479 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
82 Runtime error 481 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
83 Runtime error 399 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
84 Runtime error 394 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
85 Runtime error 402 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
86 Runtime error 441 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
87 Runtime error 389 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
88 Runtime error 357 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
89 Runtime error 335 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
90 Runtime error 350 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
91 Runtime error 345 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
92 Runtime error 349 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)