Submission #696121

# Submission time Handle Problem Language Result Execution time Memory
696121 2023-02-05T15:00:55 Z North1304 Mecho (IOI09_mecho) C++17
12 / 100
246 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
char str[801][801];
int dism[801][801],disb[801][801],n,s;
int rm,cm,rd,cd;
vector<pair<int,int>> dir = {{-1,0},{0,-1},{1,0},{0,1}};
queue<tuple<int,int,int>> q;
queue<pair<int,int>> Q;
bool solve(int t) {
	if (t>=disb[rm][cm]) return false;
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=n;j++) {
			dism[i][j] = INF;
		}
	}
	dism[rm][cm] = t;
	q.push({rm, cm, 0});
	while (!q.empty()) {
		auto [x,y,cou] = q.front(); q.pop();
		if (dism[x][y]==INF) continue;
		for(auto [di,dj]:dir) {
			int xx = x + di, yy = y + dj;
			int next = dism[x][y] + ((cou+1)%s == 0);
			if (xx<1 || xx>n || yy<1 || yy>n || str[xx][yy]=='T') continue;
			if (next < disb[xx][yy]) {
				dism[xx][yy] = next;
				q.push({xx, yy, cou+1});
			} 
		}
	}
	return dism[rd][cd] != INF;
}

int main(){
	cin >> n >> s;
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=n;j++) {
			cin >> str[i][j];
			dism[i][j] = disb[i][j] = INF;
			if (str[i][j]=='M') rm = i, cm = j;
			else if (str[i][j]=='D') rd = i, cd = j;
			else if (str[i][j]=='H') {
				disb[i][j] = 0;
				Q.push({i, j});
			}
		}
	}
	while (!Q.empty()) {
		auto [a,b] = Q.front(); Q.pop();
		for(auto [di,dj]:dir) {
			int aa = a + di, bb = b + dj;
			if (aa<1 || aa>n || bb<1 || bb>n || str[aa][bb]=='T' || str[aa][bb]=='D') continue;
			if (disb[aa][bb]>disb[a][b]+1) {
				disb[aa][bb] = disb[a][b]+1;
				Q.push({aa,bb});
			}
		}
	}
	int l=1,r=n*n,ans;
	while (l<r) {
		int mid = (l + r) / 2;
		if (solve(mid)) l = mid + 1, ans = mid; 
		else r = mid - 1;
	}
	cout << ans;
}

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:66:10: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   66 |  cout << ans;
      |          ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 312 KB Output isn't correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Correct 1 ms 312 KB Output is correct
5 Incorrect 1 ms 312 KB Output isn't correct
6 Correct 89 ms 10828 KB Output is correct
7 Runtime error 183 ms 65536 KB Execution killed with signal 9
8 Incorrect 1 ms 368 KB Output isn't correct
9 Runtime error 219 ms 65536 KB Execution killed with signal 9
10 Incorrect 5 ms 852 KB Output isn't correct
11 Runtime error 183 ms 65536 KB Execution killed with signal 9
12 Correct 1 ms 724 KB Output is correct
13 Incorrect 1 ms 596 KB Output isn't correct
14 Runtime error 144 ms 65536 KB Execution killed with signal 9
15 Runtime error 168 ms 65536 KB Execution killed with signal 9
16 Runtime error 172 ms 65536 KB Execution killed with signal 9
17 Runtime error 192 ms 65536 KB Execution killed with signal 9
18 Runtime error 173 ms 65536 KB Execution killed with signal 9
19 Runtime error 181 ms 65536 KB Execution killed with signal 9
20 Runtime error 205 ms 65536 KB Execution killed with signal 9
21 Runtime error 174 ms 65536 KB Execution killed with signal 9
22 Runtime error 175 ms 65536 KB Execution killed with signal 9
23 Runtime error 199 ms 65536 KB Execution killed with signal 9
24 Runtime error 169 ms 65536 KB Execution killed with signal 9
25 Runtime error 163 ms 65536 KB Execution killed with signal 9
26 Runtime error 170 ms 65536 KB Execution killed with signal 9
27 Runtime error 172 ms 65536 KB Execution killed with signal 9
28 Runtime error 170 ms 65536 KB Execution killed with signal 9
29 Runtime error 168 ms 65536 KB Execution killed with signal 9
30 Runtime error 175 ms 65536 KB Execution killed with signal 9
31 Runtime error 164 ms 65536 KB Execution killed with signal 9
32 Runtime error 169 ms 65536 KB Execution killed with signal 9
33 Runtime error 166 ms 65536 KB Execution killed with signal 9
34 Runtime error 179 ms 65536 KB Execution killed with signal 9
35 Runtime error 179 ms 65536 KB Execution killed with signal 9
36 Runtime error 177 ms 65536 KB Execution killed with signal 9
37 Runtime error 191 ms 65536 KB Execution killed with signal 9
38 Runtime error 176 ms 65536 KB Execution killed with signal 9
39 Runtime error 170 ms 65536 KB Execution killed with signal 9
40 Runtime error 184 ms 65536 KB Execution killed with signal 9
41 Runtime error 177 ms 65536 KB Execution killed with signal 9
42 Runtime error 176 ms 65536 KB Execution killed with signal 9
43 Runtime error 175 ms 65536 KB Execution killed with signal 9
44 Runtime error 181 ms 65536 KB Execution killed with signal 9
45 Runtime error 179 ms 65536 KB Execution killed with signal 9
46 Runtime error 177 ms 65536 KB Execution killed with signal 9
47 Runtime error 181 ms 65536 KB Execution killed with signal 9
48 Runtime error 180 ms 65536 KB Execution killed with signal 9
49 Runtime error 186 ms 65536 KB Execution killed with signal 9
50 Runtime error 205 ms 65536 KB Execution killed with signal 9
51 Runtime error 182 ms 65536 KB Execution killed with signal 9
52 Runtime error 203 ms 65536 KB Execution killed with signal 9
53 Runtime error 194 ms 65536 KB Execution killed with signal 9
54 Runtime error 184 ms 65536 KB Execution killed with signal 9
55 Runtime error 188 ms 65536 KB Execution killed with signal 9
56 Runtime error 189 ms 65536 KB Execution killed with signal 9
57 Runtime error 205 ms 65536 KB Execution killed with signal 9
58 Runtime error 192 ms 65536 KB Execution killed with signal 9
59 Runtime error 233 ms 65536 KB Execution killed with signal 9
60 Runtime error 208 ms 65536 KB Execution killed with signal 9
61 Runtime error 200 ms 65536 KB Execution killed with signal 9
62 Runtime error 246 ms 65536 KB Execution killed with signal 9
63 Runtime error 213 ms 65536 KB Execution killed with signal 9
64 Runtime error 204 ms 65536 KB Execution killed with signal 9
65 Runtime error 214 ms 65536 KB Execution killed with signal 9
66 Runtime error 209 ms 65536 KB Execution killed with signal 9
67 Runtime error 230 ms 65536 KB Execution killed with signal 9
68 Runtime error 212 ms 65536 KB Execution killed with signal 9
69 Runtime error 215 ms 65536 KB Execution killed with signal 9
70 Runtime error 209 ms 65536 KB Execution killed with signal 9
71 Runtime error 225 ms 65536 KB Execution killed with signal 9
72 Runtime error 201 ms 65536 KB Execution killed with signal 9
73 Incorrect 56 ms 6732 KB Output isn't correct
74 Runtime error 168 ms 65536 KB Execution killed with signal 9
75 Runtime error 170 ms 65536 KB Execution killed with signal 9
76 Runtime error 166 ms 65536 KB Execution killed with signal 9
77 Runtime error 163 ms 65536 KB Execution killed with signal 9
78 Runtime error 166 ms 65536 KB Execution killed with signal 9
79 Runtime error 161 ms 65536 KB Execution killed with signal 9
80 Runtime error 159 ms 65536 KB Execution killed with signal 9
81 Runtime error 166 ms 65536 KB Execution killed with signal 9
82 Runtime error 170 ms 65536 KB Execution killed with signal 9
83 Runtime error 181 ms 65536 KB Execution killed with signal 9
84 Runtime error 172 ms 65536 KB Execution killed with signal 9
85 Runtime error 194 ms 65536 KB Execution killed with signal 9
86 Runtime error 162 ms 65536 KB Execution killed with signal 9
87 Runtime error 163 ms 65536 KB Execution killed with signal 9
88 Runtime error 169 ms 65536 KB Execution killed with signal 9
89 Runtime error 167 ms 65536 KB Execution killed with signal 9
90 Runtime error 165 ms 65536 KB Execution killed with signal 9
91 Runtime error 172 ms 65536 KB Execution killed with signal 9
92 Runtime error 168 ms 65536 KB Execution killed with signal 9