답안 #386591

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386591 2021-04-07T03:38:17 Z Kepha 악어의 지하 도시 (IOI11_crocodile) C++11
100 / 100
809 ms 64480 KB
#include "crocodile.h"
#include<algorithm>
#include<vector>
using namespace std;
vector<int>E[100100], Len[101000];
bool chk[101000];
struct HP{
	int d, num;
	bool operator<(const HP &p)const{
		return d>p.d;
	}
}Heap[8000100];
int D[100100][2], top;
void Add(int a, int b){
	if (D[a][1] <= b)return;
	if (D[a][0] > b){
		D[a][1] = D[a][0]; D[a][0] = b;
	}
	else if (D[a][1] > b)D[a][1] = b;
	Heap[top].d = b;
	Heap[top].num = a;
	top++;
	push_heap(Heap, Heap + top);
}
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
	int i, x;
	HP t;
	for (i = 0; i < M; i++){
		E[R[i][0]].push_back(R[i][1]);
		E[R[i][1]].push_back(R[i][0]);
		Len[R[i][0]].push_back(L[i]);
		Len[R[i][1]].push_back(L[i]);
	}
	for (i = 0; i < N; i++)D[i][0] = D[i][1] = 2100000000;
	top = 0;
	for (i = 0; i < K; i++){
		D[P[i]][0] = 0;
		Add(P[i], 0);
	}
	while (1){
		while (top){
			t = Heap[0];
			if (D[t.num][1] == t.d && !chk[t.num])break;
			pop_heap(Heap, Heap + top);
			top--;
		}
		chk[t.num] = true;
		if (t.num == 0)break;
		pop_heap(Heap, Heap + top);
		top--;
		for (i = 0; i < E[t.num].size(); i++){
			Add(E[t.num][i], t.d + Len[t.num][i]);
		}
	}
	return D[0][1];
}

Compilation message

crocodile.cpp: In function 'int travel_plan(int, int, int (*)[2], int*, int, int*)':
crocodile.cpp:52:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |   for (i = 0; i < E[t.num].size(); i++){
      |               ~~^~~~~~~~~~~~~~~~~
crocodile.cpp:27:9: warning: unused variable 'x' [-Wunused-variable]
   27 |  int i, x;
      |         ^
crocodile.cpp:49:3: warning: 't.HP::num' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |   if (t.num == 0)break;
      |   ^~
crocodile.cpp:53:7: warning: 't.HP::d' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |    Add(E[t.num][i], t.d + Len[t.num][i]);
      |    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 5 ms 5120 KB Output is correct
5 Correct 5 ms 5228 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5248 KB Output is correct
8 Correct 4 ms 5228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 5 ms 5120 KB Output is correct
5 Correct 5 ms 5228 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5248 KB Output is correct
8 Correct 4 ms 5228 KB Output is correct
9 Correct 6 ms 5356 KB Output is correct
10 Correct 4 ms 5100 KB Output is correct
11 Correct 5 ms 5228 KB Output is correct
12 Correct 8 ms 5484 KB Output is correct
13 Correct 9 ms 5612 KB Output is correct
14 Correct 5 ms 5100 KB Output is correct
15 Correct 5 ms 5228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB Output is correct
2 Correct 4 ms 5100 KB Output is correct
3 Correct 4 ms 5100 KB Output is correct
4 Correct 5 ms 5120 KB Output is correct
5 Correct 5 ms 5228 KB Output is correct
6 Correct 4 ms 5100 KB Output is correct
7 Correct 4 ms 5248 KB Output is correct
8 Correct 4 ms 5228 KB Output is correct
9 Correct 6 ms 5356 KB Output is correct
10 Correct 4 ms 5100 KB Output is correct
11 Correct 5 ms 5228 KB Output is correct
12 Correct 8 ms 5484 KB Output is correct
13 Correct 9 ms 5612 KB Output is correct
14 Correct 5 ms 5100 KB Output is correct
15 Correct 5 ms 5228 KB Output is correct
16 Correct 588 ms 59664 KB Output is correct
17 Correct 95 ms 17864 KB Output is correct
18 Correct 119 ms 19564 KB Output is correct
19 Correct 809 ms 64480 KB Output is correct
20 Correct 337 ms 52776 KB Output is correct
21 Correct 50 ms 10604 KB Output is correct
22 Correct 376 ms 49004 KB Output is correct