Submission #92024

# Submission time Handle Problem Language Result Execution time Memory
92024 2019-01-01T06:29:32 Z arman_ferdous Mecho (IOI09_mecho) C++17
6 / 100
554 ms 66560 KB
#include <bits/stdc++.h>
using namespace std;
 
#define xx first
#define yy second
typedef pair<int,int> ii;
const int N = 104;
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 256 KB Output isn't correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Incorrect 2 ms 256 KB Output isn't correct
4 Incorrect 2 ms 256 KB Output isn't correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Incorrect 2 ms 376 KB Output isn't correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Incorrect 2 ms 376 KB Output isn't correct
13 Runtime error 552 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
14 Runtime error 554 ms 66560 KB Execution killed with signal 9 (could be triggered by violating memory limits)
15 Incorrect 2 ms 376 KB Output isn't correct
16 Incorrect 2 ms 376 KB Output isn't correct
17 Incorrect 2 ms 380 KB Output isn't correct
18 Incorrect 2 ms 376 KB Output isn't correct
19 Incorrect 2 ms 376 KB Output isn't correct
20 Incorrect 2 ms 376 KB Output isn't correct
21 Incorrect 2 ms 376 KB Output isn't correct
22 Incorrect 2 ms 376 KB Output isn't correct
23 Incorrect 2 ms 376 KB Output isn't correct
24 Incorrect 2 ms 380 KB Output isn't correct
25 Incorrect 2 ms 380 KB Output isn't correct
26 Incorrect 2 ms 376 KB Output isn't correct
27 Incorrect 2 ms 376 KB Output isn't correct
28 Incorrect 2 ms 376 KB Output isn't correct
29 Incorrect 2 ms 376 KB Output isn't correct
30 Incorrect 2 ms 376 KB Output isn't correct
31 Incorrect 2 ms 376 KB Output isn't correct
32 Incorrect 2 ms 376 KB Output isn't correct
33 Runtime error 3 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
35 Runtime error 2 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Runtime error 3 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
37 Runtime error 3 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
38 Runtime error 3 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
39 Runtime error 3 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
40 Runtime error 3 ms 760 KB Execution killed with signal 11 (could be triggered by violating memory limits)
41 Runtime error 3 ms 880 KB Execution killed with signal 11 (could be triggered by violating memory limits)
42 Runtime error 3 ms 888 KB Execution killed with signal 11 (could be triggered by violating memory limits)
43 Runtime error 3 ms 888 KB Execution killed with signal 11 (could be triggered by violating memory limits)
44 Runtime error 3 ms 888 KB Execution killed with signal 11 (could be triggered by violating memory limits)
45 Runtime error 3 ms 888 KB Execution killed with signal 11 (could be triggered by violating memory limits)
46 Runtime error 4 ms 892 KB Execution killed with signal 11 (could be triggered by violating memory limits)
47 Runtime error 3 ms 888 KB Execution killed with signal 11 (could be triggered by violating memory limits)
48 Runtime error 3 ms 1016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
49 Runtime error 3 ms 1016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
50 Runtime error 3 ms 888 KB Execution killed with signal 11 (could be triggered by violating memory limits)
51 Runtime error 3 ms 1016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
52 Runtime error 4 ms 1144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
53 Runtime error 4 ms 1016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
54 Runtime error 4 ms 1016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
55 Runtime error 4 ms 1016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
56 Runtime error 4 ms 1016 KB Execution killed with signal 11 (could be triggered by violating memory limits)
57 Runtime error 4 ms 1244 KB Execution killed with signal 11 (could be triggered by violating memory limits)
58 Runtime error 4 ms 1400 KB Execution killed with signal 11 (could be triggered by violating memory limits)
59 Runtime error 4 ms 1144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
60 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
61 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
62 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
63 Runtime error 5 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
64 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
65 Runtime error 4 ms 1276 KB Execution killed with signal 11 (could be triggered by violating memory limits)
66 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
67 Runtime error 4 ms 1276 KB Execution killed with signal 11 (could be triggered by violating memory limits)
68 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
69 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
70 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
71 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
72 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
73 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
74 Runtime error 4 ms 1276 KB Execution killed with signal 11 (could be triggered by violating memory limits)
75 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
76 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
77 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
78 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
79 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
80 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
81 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
82 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
83 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
84 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
85 Runtime error 5 ms 1144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
86 Runtime error 4 ms 1144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
87 Runtime error 4 ms 1144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
88 Runtime error 4 ms 1144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
89 Runtime error 4 ms 1144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
90 Runtime error 5 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)
91 Runtime error 4 ms 1144 KB Execution killed with signal 11 (could be triggered by violating memory limits)
92 Runtime error 4 ms 1272 KB Execution killed with signal 11 (could be triggered by violating memory limits)