답안 #211370

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211370 2020-03-20T08:19:54 Z socho 악어의 지하 도시 (IOI11_crocodile) C++14
89 / 100
2000 ms 110808 KB
#include "crocodile.h"
#include "bits/stdc++.h"
using namespace std;
// #define endl '\n'
// #define int long long

int n, m;
const int MXN = 100005;
vector<pair<int, int> > adj[MXN];
bool ter[MXN], assign[MXN];
int dist[MXN];
int via[MXN];



int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
  
	n = N, m = M;
	for (int i=0; i<m; i++) {
		int a, b, w;
		a = R[i][0], b = R[i][1], w = L[i];
		adj[a].push_back(make_pair(b, w));
		adj[b].push_back(make_pair(a, w));
	}
	
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > pro;
	multiset<int> poss[MXN];
	bool done[MXN];
	
	for (int i=0; i<MXN; i++) dist[i] = INT_MAX;
	
	int k = K;
	for (int i=0; i<k; i++) {
		int x = P[i];
		ter[x] = true;
		dist[x] = 0;
		done[x] = true;
		pro.push(make_pair(0, x));
	}

	set<int> pend;
	
	while (!pro.empty() || !pend.empty()) {
		
		while (!pend.empty()) {
			int X = *pend.begin(); pend.erase(pend.begin());
			pro.push(make_pair(*(++poss[X].begin()), X));
		}
		
		int di = pro.top().first;
		int no = pro.top().second;
		pro.pop();
		
		if (dist[no] < di) continue; // do not relax

		if (poss[no].size() >= 2 && !done[no]) {
			// can assign second dist, first relaxing
			done[no] = true;
			dist[no] = *(++poss[no].begin());
		}
		
		if (done[no] && !assign[no]) {
			assign[no] = true;
			// can access adjs
			for (int i=0; i<adj[no].size(); i++) {
				// cout << "add option: " << no << " to " << adj[no][i].first << endl;
				int f = adj[no][i].second;
				poss[adj[no][i].first].insert(f + dist[no]);
				if (poss[adj[no][i].first].size() >= 2) {
					//sort(poss[adj[no][i].first].begin(), poss[adj[no][i].first].end());
					pend.insert(adj[no][i].first);
				}
			}
		}

	}
	
	assert(dist[0] != INT_MAX);
	return dist[0];
  
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:66:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int i=0; i<adj[no].size(); i++) {
                  ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7808 KB Output is correct
2 Correct 9 ms 7808 KB Output is correct
3 Correct 9 ms 7808 KB Output is correct
4 Correct 9 ms 7936 KB Output is correct
5 Correct 10 ms 7936 KB Output is correct
6 Correct 9 ms 7936 KB Output is correct
7 Correct 9 ms 7936 KB Output is correct
8 Correct 10 ms 7936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7808 KB Output is correct
2 Correct 9 ms 7808 KB Output is correct
3 Correct 9 ms 7808 KB Output is correct
4 Correct 9 ms 7936 KB Output is correct
5 Correct 10 ms 7936 KB Output is correct
6 Correct 9 ms 7936 KB Output is correct
7 Correct 9 ms 7936 KB Output is correct
8 Correct 10 ms 7936 KB Output is correct
9 Correct 15 ms 8448 KB Output is correct
10 Correct 8 ms 7808 KB Output is correct
11 Correct 14 ms 8064 KB Output is correct
12 Correct 27 ms 9088 KB Output is correct
13 Correct 19 ms 9216 KB Output is correct
14 Correct 9 ms 7808 KB Output is correct
15 Correct 11 ms 8064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7808 KB Output is correct
2 Correct 9 ms 7808 KB Output is correct
3 Correct 9 ms 7808 KB Output is correct
4 Correct 9 ms 7936 KB Output is correct
5 Correct 10 ms 7936 KB Output is correct
6 Correct 9 ms 7936 KB Output is correct
7 Correct 9 ms 7936 KB Output is correct
8 Correct 10 ms 7936 KB Output is correct
9 Correct 15 ms 8448 KB Output is correct
10 Correct 8 ms 7808 KB Output is correct
11 Correct 14 ms 8064 KB Output is correct
12 Correct 27 ms 9088 KB Output is correct
13 Correct 19 ms 9216 KB Output is correct
14 Correct 9 ms 7808 KB Output is correct
15 Correct 11 ms 8064 KB Output is correct
16 Execution timed out 2096 ms 110808 KB Time limit exceeded
17 Halted 0 ms 0 KB -