답안 #1065620

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065620 2024-08-19T10:02:35 Z belgianbot Mecho (IOI09_mecho) C++17
40 / 100
1000 ms 65536 KB
#include <bits/stdc++.h>
#define int long long
#define se second
#define fi first

using namespace std;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, S; cin >> N >> S;
	vector<vector<char>> grid(N, vector<char>(N));
	
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) cin >> grid[i][j];
	}
	
	int start, end;
	vector<vector<int>> adj(N * N);
	vector<int> hives;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (grid[i][j] == 'H') hives.push_back(i * N + j);
			else if (grid[i][j] == 'M') start = i * N + j;
			else if (grid[i][j] == 'D') end = i * N + j;
			if (grid[i][j] != 'G') continue;
			if (i && (grid[i - 1][j] == 'D' || grid[i - 1][j] == 'H' || grid[i - 1][j] == 'M' || grid[i - 1][j] == 'G')) adj[i * N - N + j].push_back(i * N + j);
			if (j && (grid[i][j-1] == 'D' || grid[i][j-1] == 'H' || grid[i][j-1] == 'M' || grid[i][j-1] == 'G')) adj[i * N + j-1].push_back(i * N + j);
			if (i != N - 1 && (grid[i + 1][j] == 'D' || grid[i + 1][j] == 'H' || grid[i + 1][j] == 'M' || grid[i + 1][j] == 'G')) adj[i * N + N + j].push_back(i * N + j);
			if (j != N - 1 && (grid[i][j+1] == 'D' || grid[i][j+1] == 'H' || grid[i][j+1] == 'M' || grid[i][j+1] == 'G')) adj[i * N + j+1].push_back(i * N + j);
		}
	}
	
	vector<int> dist(N * N, INT_MAX);
	for (int x : hives) {
		priority_queue<pair<int,int>> q;
		q.push({0,x});
		set<int> processed;
		dist[x] = 0;
		
		while(!q.empty()) {
			auto u = q.top(); q.pop();
			if (processed.find(u.se) != processed.end()) continue;
			processed.insert(u.se);
			
			for (int y : adj[u.se]) {
				if (-u.fi + 1 < dist[y]) {
					dist[y] = -u.fi + 1;
					q.push({-dist[y], y});
				}
			}
		}
	}
	
	int l = 1, r = N * N;
	while (l <= r) {
		int mid = l + (r - l) / 2;
		
		vector<double> mecho(N * N, INT_MAX);
		mecho[start] = mid;
		priority_queue<pair<double,int>> q;
		q.push({double(-mid), start});
		set<int> processed;
		
		while(!q.empty()) {
			auto u = q.top(); q.pop();
			if (processed.find(u.se) != processed.end()) continue;
			processed.insert(u.se);
			
			for (int y : adj[u.se]) {
				if (-u.fi + 1.0 / double(S) < dist[y] && -u.fi + 1.0 / double(S) < mecho[y]) {
					mecho[y] = -u.fi + 1.0 / double(S);
					q.push({-mecho[y], y});
				}
			}
		}
		bool won = false;
		for (int y : adj[end]) if (mecho[y] != INT_MAX) won = true;
		if (won) l = mid + 1;
		else r = mid - 1;
	}
	cout << l - 1 << '\n';
	
	return 0;
}
		
	
	
	

Compilation message

mecho.cpp: In function 'int main()':
mecho.cpp:60:14: warning: 'start' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |   mecho[start] = mid;
      |              ^
mecho.cpp:78:23: warning: 'end' may be used uninitialized in this function [-Wmaybe-uninitialized]
   78 |   for (int y : adj[end]) if (mecho[y] != INT_MAX) won = true;
      |                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 408 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Runtime error 210 ms 65536 KB Execution killed with signal 9
8 Incorrect 1 ms 348 KB Output isn't correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 1 ms 604 KB Output isn't correct
13 Incorrect 5 ms 604 KB Output isn't correct
14 Incorrect 8 ms 860 KB Output isn't correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 456 KB Output is correct
24 Correct 1 ms 452 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 716 KB Output is correct
28 Correct 2 ms 712 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 860 KB Output is correct
32 Correct 1 ms 860 KB Output is correct
33 Correct 23 ms 9304 KB Output is correct
34 Correct 28 ms 10076 KB Output is correct
35 Correct 278 ms 13504 KB Output is correct
36 Correct 32 ms 11944 KB Output is correct
37 Correct 38 ms 13140 KB Output is correct
38 Correct 398 ms 17520 KB Output is correct
39 Correct 48 ms 15128 KB Output is correct
40 Correct 54 ms 16544 KB Output is correct
41 Correct 544 ms 22144 KB Output is correct
42 Correct 46 ms 18468 KB Output is correct
43 Correct 89 ms 20308 KB Output is correct
44 Correct 753 ms 27188 KB Output is correct
45 Correct 53 ms 22212 KB Output is correct
46 Correct 81 ms 24664 KB Output is correct
47 Correct 869 ms 32884 KB Output is correct
48 Correct 66 ms 26452 KB Output is correct
49 Correct 88 ms 29268 KB Output is correct
50 Execution timed out 1008 ms 39056 KB Time limit exceeded
51 Correct 84 ms 31104 KB Output is correct
52 Correct 112 ms 34228 KB Output is correct
53 Execution timed out 1056 ms 45632 KB Time limit exceeded
54 Correct 100 ms 35924 KB Output is correct
55 Correct 129 ms 39748 KB Output is correct
56 Execution timed out 1052 ms 52916 KB Time limit exceeded
57 Correct 111 ms 41004 KB Output is correct
58 Correct 161 ms 45396 KB Output is correct
59 Execution timed out 1020 ms 60468 KB Time limit exceeded
60 Correct 126 ms 46676 KB Output is correct
61 Correct 172 ms 51792 KB Output is correct
62 Runtime error 881 ms 65536 KB Execution killed with signal 9
63 Execution timed out 1056 ms 53076 KB Time limit exceeded
64 Execution timed out 1016 ms 56604 KB Time limit exceeded
65 Execution timed out 1034 ms 56364 KB Time limit exceeded
66 Execution timed out 1037 ms 53180 KB Time limit exceeded
67 Execution timed out 1049 ms 53072 KB Time limit exceeded
68 Execution timed out 1042 ms 53072 KB Time limit exceeded
69 Execution timed out 1094 ms 53144 KB Time limit exceeded
70 Execution timed out 1070 ms 53176 KB Time limit exceeded
71 Execution timed out 1078 ms 53184 KB Time limit exceeded
72 Execution timed out 1084 ms 52740 KB Time limit exceeded
73 Runtime error 225 ms 65536 KB Execution killed with signal 9
74 Runtime error 207 ms 65536 KB Execution killed with signal 9
75 Runtime error 212 ms 65536 KB Execution killed with signal 9
76 Runtime error 206 ms 65536 KB Execution killed with signal 9
77 Runtime error 216 ms 65536 KB Execution killed with signal 9
78 Runtime error 205 ms 65536 KB Execution killed with signal 9
79 Runtime error 234 ms 65536 KB Execution killed with signal 9
80 Runtime error 223 ms 65536 KB Execution killed with signal 9
81 Runtime error 252 ms 65536 KB Execution killed with signal 9
82 Runtime error 215 ms 65536 KB Execution killed with signal 9
83 Runtime error 215 ms 65536 KB Execution killed with signal 9
84 Runtime error 228 ms 65536 KB Execution killed with signal 9
85 Runtime error 242 ms 65536 KB Execution killed with signal 9
86 Runtime error 211 ms 65536 KB Execution killed with signal 9
87 Runtime error 235 ms 65536 KB Execution killed with signal 9
88 Runtime error 217 ms 65536 KB Execution killed with signal 9
89 Runtime error 247 ms 65536 KB Execution killed with signal 9
90 Runtime error 249 ms 65536 KB Execution killed with signal 9
91 Runtime error 233 ms 65536 KB Execution killed with signal 9
92 Runtime error 230 ms 65536 KB Execution killed with signal 9