답안 #205349

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
205349 2020-02-28T15:56:39 Z mode149256 악어의 지하 도시 (IOI11_crocodile) C++14
100 / 100
960 ms 77164 KB
/*input

*/
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;

#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"

const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;

template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }

template<typename T>
void print(vector<T> vec, string name = "") {
	cout << name;
	for (auto u : vec)
		cout << u << ' ';
	cout << '\n';
}

const ll DID = (ll)1e17;

int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
	vector<vpl> edges(N);
	{
		for (int i = 0; i < M; ++i)
		{
			int a = R[i][0];
			int b = R[i][1];
			edges[a].emplace_back(b, L[i]);
			edges[b].emplace_back(a, L[i]);
		}
	}

	vll dis(N, vl(2, DID));
	vll iskur(N, vl(2, -1));

	priority_queue<pl, vpl, greater<pl>> pq;

	for (int i = 0; i < K; ++i)
	{
		int c = P[i];
		dis[c][0] = dis[c][1] = 0;
		iskur[c][0] = iskur[c][1] = c;
		pq.push({0, c});
	}

	while (pq.size()) {
		pl dab = pq.top(); pq.pop();

		int c = (int)dab.y;
		ll d = dab.x;
		if (d > dis[c][1]) continue;

		for (auto u : edges[c]) {
			ll newDis = d + u.y;
			if (c == iskur[u.x][0]) {
				dis[u.x][0] = min(newDis, dis[u.x][0]);
			} else if (c == iskur[u.x][1]) {
				dis[u.x][1] = min(newDis, dis[u.x][1]);

				if (dis[u.x][1] < dis[u.x][0]) {
					swap(dis[u.x][0], dis[u.x][1]);
					swap(iskur[u.x][0], iskur[u.x][1]);
				}
			}
			else {
				if (newDis <= dis[u.x][0]) {
					dis[u.x][1] = dis[u.x][0];
					iskur[u.x][1] = iskur[u.x][0];
					dis[u.x][0] = newDis;
					iskur[u.x][0] = c;

					if (dis[u.x][1] != DID)
						pq.push({dis[u.x][1], u.x});
				} else if (newDis < dis[u.x][1]) {
					dis[u.x][1] = newDis;
					iskur[u.x][1] = c;

					pq.push({dis[u.x][1], u.x});
				}
			}
		}
	}

	return dis[0][1];
}


/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 6 ms 632 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 6 ms 632 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 7 ms 632 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 9 ms 888 KB Output is correct
13 Correct 8 ms 1016 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 6 ms 632 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 7 ms 632 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 9 ms 888 KB Output is correct
13 Correct 8 ms 1016 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 685 ms 66356 KB Output is correct
17 Correct 112 ms 23928 KB Output is correct
18 Correct 154 ms 25336 KB Output is correct
19 Correct 960 ms 77164 KB Output is correct
20 Correct 364 ms 52732 KB Output is correct
21 Correct 54 ms 9468 KB Output is correct
22 Correct 401 ms 51064 KB Output is correct