Submission #205345

# Submission time Handle Problem Language Result Execution time Memory
205345 2020-02-28T15:41:54 Z mode149256 Crocodile's Underground City (IOI11_crocodile) C++14
89 / 100
906 ms 73744 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)1e15;

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));
	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;
		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 (newDis < dis[u.x][0]) {
				dis[u.x][1] = dis[u.x][0];
				dis[u.x][0] = newDis;

				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;
				pq.push({dis[u.x][1], u.x});
			}
		}
	}

	return (int)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
*/
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 6 ms 632 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 9 ms 888 KB Output is correct
13 Correct 9 ms 1144 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 632 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 6 ms 632 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 9 ms 888 KB Output is correct
13 Correct 9 ms 1144 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 634 ms 65620 KB Output is correct
17 Correct 109 ms 18424 KB Output is correct
18 Correct 141 ms 19832 KB Output is correct
19 Correct 906 ms 73744 KB Output is correct
20 Correct 366 ms 52832 KB Output is correct
21 Correct 51 ms 7928 KB Output is correct
22 Incorrect 388 ms 49528 KB Output isn't correct