답안 #1114785

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114785 2024-11-19T15:38:29 Z sosuke 악어의 지하 도시 (IOI11_crocodile) C++14
100 / 100
335 ms 62620 KB
#include <bits/stdc++.h>
using namespace std;

int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
	vector<vector<array<int, 2>>> adj(n);
	for (int i = 0; i < m; i++) {
		adj[r[i][0]].push_back({r[i][1], l[i]});
		adj[r[i][1]].push_back({r[i][0], l[i]});
	}

	// we use 1e9 instead of INT_MAX to prevent overflow
	const array<int, 2> DEF = {(int)1e9, (int)1e9};
	vector<array<int, 2>> dist(n, DEF);
	priority_queue<array<int, 2>> pq;
	for (int i = 0; i < k; i++) {
		pq.push({0, p[i]});
		dist[p[i]] = {0, 0};
	}

	while (!pq.empty()) {
		auto [time, at] = pq.top();
		pq.pop();
		time *= -1;  // undoing the negative number trick
		if (dist[at][1] < time) { continue; }
		for (const auto [nxt, weight] : adj[at]) {
			if (time + weight < dist[nxt][0]) {
				if (dist[nxt][0] < dist[nxt][1]) { pq.push({-dist[nxt][0], nxt}); }
				dist[nxt][1] = dist[nxt][0];
				dist[nxt][0] = time + weight;
			} else if (time + weight < dist[nxt][1]) {
				dist[nxt][1] = time + weight;
				pq.push({-dist[nxt][1], nxt});
			}
		}
	}
	return dist[0][1];
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:21:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   21 |   auto [time, at] = pq.top();
      |        ^
crocodile.cpp:25:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   25 |   for (const auto [nxt, weight] : adj[at]) {
      |                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 2 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 2 ms 4432 KB Output is correct
9 Correct 2 ms 4688 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 2 ms 4460 KB Output is correct
12 Correct 4 ms 4688 KB Output is correct
13 Correct 5 ms 4944 KB Output is correct
14 Correct 1 ms 4604 KB Output is correct
15 Correct 2 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 2 ms 4432 KB Output is correct
5 Correct 2 ms 4432 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 2 ms 4432 KB Output is correct
8 Correct 2 ms 4432 KB Output is correct
9 Correct 2 ms 4688 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 2 ms 4460 KB Output is correct
12 Correct 4 ms 4688 KB Output is correct
13 Correct 5 ms 4944 KB Output is correct
14 Correct 1 ms 4604 KB Output is correct
15 Correct 2 ms 4432 KB Output is correct
16 Correct 272 ms 56484 KB Output is correct
17 Correct 58 ms 15524 KB Output is correct
18 Correct 62 ms 16916 KB Output is correct
19 Correct 335 ms 62620 KB Output is correct
20 Correct 237 ms 47944 KB Output is correct
21 Correct 26 ms 9044 KB Output is correct
22 Correct 205 ms 46020 KB Output is correct