답안 #108517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108517 2019-04-30T06:29:07 Z E869120 Amusement Park (JOI17_amusement_park) C++14
83 / 100
1016 ms 4180 KB
#include "Joi.h"
#include <iostream>
#include <vector>
using namespace std;

vector<int>G[10009]; int col[10009], cnts;

void dfs(int pos) {
	if (col[pos] >= 0) return;
	col[pos] = cnts % 60; cnts++;
	for (int i = 0; i < G[pos].size(); i++) dfs(G[pos][i]);
}

void Joi(int N, int M, int A[], int B[], long long X, int T) {
	for (int i = 0; i < M; i++) { G[A[i]].push_back(B[i]); G[B[i]].push_back(A[i]); }
	for (int i = 0; i < N; i++) col[i] = -1;
	dfs(0);
	for (int i = 0; i < N; i++) MessageBoard(i, (X / (1LL << col[i])) % 2);
}
#include "Ioi.h"
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

vector<int>I[10009]; int dist[10009], par[10009], cols[10009], cntv;
int N, M; bool used[60];

void dfs2(int pos) {
	if (cols[pos] >= 0) return;
	cols[pos] = cntv % 60; cntv++;
	for (int i = 0; i < I[pos].size(); i++) dfs2(I[pos][i]);
}

vector<int> nearest(int sta, int rem) {
	for (int i = 0; i < N; i++) dist[i] = (1 << 30);
	
	queue<int>Q; Q.push(sta); dist[sta] = 0;
	while (!Q.empty()) {
		int pos = Q.front(); Q.pop();
		for (int i = 0; i < I[pos].size(); i++) {
			int to = I[pos][i];
			if (dist[to] > dist[pos] + 1) {
				dist[to] = dist[pos] + 1;
				par[to] = pos;
				Q.push(to);
			}
		}
	}

	int id = 0, minx = 10000;
	for (int i = 0; i < N; i++) {
		if (cols[i] == rem && dist[i] < minx) {
			minx = dist[i]; id = i;
		}
	}

	vector<int>U;
	while (true) {
		U.push_back(id); if (id == sta) break;
		id = par[id];
	}
	reverse(U.begin(), U.end());
	return U;
}

long long Ioi(int NN, int MM, int A[], int B[], int P, int V, int T) {
	N = NN; M = MM;
	for (int i = 0; i < M; i++) { I[A[i]].push_back(B[i]); I[B[i]].push_back(A[i]); }
	for (int i = 0; i < N; i++) cols[i] = -1;
	dfs2(0);
	
	int cx = P; long long rem = 0;
	for (int i = 0; i < 60; i++) {
		vector<int>E; int id = -1;
		for (int j = 0; j < 60; j++) {
			if (used[j] == true) continue;
			vector<int>F = nearest(cx, j);
			if (E.size() == 0 || E.size() > F.size()) { E = F; id = j; }
		}
		int F = V;
		for (int j = 1; j < E.size(); j++) {
			F = Move(E[j]);
		}
		rem += 1LL * F * (1LL << id);
		if (E.size() >= 1) cx = E[E.size() - 1];
		used[id] = true;
	}
	return rem;
}

Compilation message

Joi.cpp: In function 'void dfs(int)':
Joi.cpp:11:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < G[pos].size(); i++) dfs(G[pos][i]);
                  ~~^~~~~~~~~~~~~~~

Ioi.cpp: In function 'void dfs2(int)':
Ioi.cpp:13:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < I[pos].size(); i++) dfs2(I[pos][i]);
                  ~~^~~~~~~~~~~~~~~
Ioi.cpp: In function 'std::vector<int> nearest(int, int)':
Ioi.cpp:22:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < I[pos].size(); i++) {
                   ~~^~~~~~~~~~~~~~~
Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:63:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 1; j < E.size(); j++) {
                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1392 KB Output is correct
2 Correct 9 ms 1288 KB Output is correct
3 Correct 11 ms 1384 KB Output is correct
4 Correct 7 ms 1288 KB Output is correct
5 Correct 7 ms 1152 KB Output is correct
6 Correct 7 ms 1152 KB Output is correct
7 Correct 10 ms 1292 KB Output is correct
8 Correct 12 ms 1292 KB Output is correct
9 Correct 11 ms 1420 KB Output is correct
10 Correct 8 ms 1388 KB Output is correct
11 Correct 32 ms 1668 KB Output is correct
12 Correct 6 ms 1392 KB Output is correct
13 Correct 10 ms 1408 KB Output is correct
14 Correct 9 ms 1292 KB Output is correct
15 Correct 10 ms 1412 KB Output is correct
16 Correct 12 ms 1384 KB Output is correct
17 Correct 15 ms 1156 KB Output is correct
18 Correct 13 ms 1284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 963 ms 3980 KB Output is correct
2 Correct 989 ms 4064 KB Output is correct
3 Correct 1016 ms 4180 KB Output is correct
4 Correct 698 ms 2812 KB Output is correct
5 Correct 929 ms 3052 KB Output is correct
6 Correct 737 ms 3132 KB Output is correct
7 Correct 774 ms 3104 KB Output is correct
8 Correct 776 ms 3000 KB Output is correct
9 Correct 730 ms 3028 KB Output is correct
10 Correct 377 ms 2984 KB Output is correct
11 Correct 399 ms 2888 KB Output is correct
12 Correct 510 ms 2724 KB Output is correct
13 Correct 407 ms 2736 KB Output is correct
14 Correct 413 ms 2624 KB Output is correct
15 Correct 554 ms 2744 KB Output is correct
16 Correct 545 ms 2920 KB Output is correct
17 Correct 796 ms 2908 KB Output is correct
18 Correct 599 ms 2776 KB Output is correct
19 Correct 614 ms 2868 KB Output is correct
20 Correct 169 ms 3012 KB Output is correct
21 Correct 151 ms 3000 KB Output is correct
22 Correct 471 ms 2880 KB Output is correct
23 Correct 505 ms 3068 KB Output is correct
24 Correct 541 ms 3000 KB Output is correct
25 Correct 530 ms 3000 KB Output is correct
26 Correct 514 ms 3000 KB Output is correct
27 Correct 522 ms 2980 KB Output is correct
28 Correct 546 ms 2880 KB Output is correct
29 Correct 515 ms 2928 KB Output is correct
30 Correct 525 ms 2872 KB Output is correct
31 Correct 8 ms 1152 KB Output is correct
32 Correct 7 ms 1164 KB Output is correct
33 Correct 10 ms 1412 KB Output is correct
34 Correct 9 ms 1288 KB Output is correct
35 Correct 6 ms 1152 KB Output is correct
36 Correct 6 ms 1280 KB Output is correct
37 Correct 6 ms 1416 KB Output is correct
38 Correct 6 ms 1152 KB Output is correct
39 Correct 6 ms 1328 KB Output is correct
40 Correct 7 ms 1288 KB Output is correct
41 Correct 6 ms 1152 KB Output is correct
42 Correct 7 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1152 KB Output is correct
2 Correct 6 ms 1152 KB Output is correct
3 Correct 7 ms 1152 KB Output is correct
4 Correct 41 ms 1480 KB Output is correct
5 Correct 31 ms 1564 KB Output is correct
6 Correct 39 ms 1572 KB Output is correct
7 Correct 38 ms 1708 KB Output is correct
8 Correct 38 ms 1680 KB Output is correct
9 Correct 184 ms 3264 KB Output is correct
10 Correct 209 ms 3264 KB Output is correct
11 Correct 207 ms 3376 KB Output is correct
12 Correct 8 ms 1152 KB Output is correct
13 Correct 6 ms 1152 KB Output is correct
14 Correct 7 ms 1152 KB Output is correct
15 Correct 4 ms 1288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 974 ms 3980 KB Output is correct
2 Correct 1004 ms 4000 KB Output is correct
3 Correct 961 ms 4052 KB Output is correct
4 Correct 789 ms 2760 KB Output is correct
5 Correct 900 ms 3352 KB Output is correct
6 Correct 754 ms 3016 KB Output is correct
7 Correct 680 ms 3136 KB Output is correct
8 Correct 711 ms 3016 KB Output is correct
9 Correct 717 ms 3056 KB Output is correct
10 Correct 454 ms 2872 KB Output is correct
11 Correct 395 ms 2880 KB Output is correct
12 Correct 428 ms 2856 KB Output is correct
13 Correct 505 ms 2904 KB Output is correct
14 Correct 495 ms 2792 KB Output is correct
15 Correct 623 ms 2836 KB Output is correct
16 Correct 628 ms 2752 KB Output is correct
17 Correct 686 ms 2912 KB Output is correct
18 Correct 653 ms 2840 KB Output is correct
19 Correct 669 ms 2880 KB Output is correct
20 Correct 180 ms 3036 KB Output is correct
21 Correct 181 ms 3008 KB Output is correct
22 Correct 583 ms 3084 KB Output is correct
23 Correct 509 ms 3016 KB Output is correct
24 Correct 544 ms 3020 KB Output is correct
25 Correct 572 ms 3108 KB Output is correct
26 Correct 545 ms 3196 KB Output is correct
27 Correct 623 ms 3256 KB Output is correct
28 Correct 566 ms 3000 KB Output is correct
29 Correct 481 ms 2992 KB Output is correct
30 Correct 547 ms 3120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 872 ms 4120 KB Output is correct
2 Correct 907 ms 3996 KB Output is correct
3 Correct 999 ms 3908 KB Output is correct
4 Correct 732 ms 2864 KB Output is correct
5 Correct 829 ms 3364 KB Output is correct
6 Correct 797 ms 3344 KB Output is correct
7 Correct 775 ms 3108 KB Output is correct
8 Correct 748 ms 3280 KB Output is correct
9 Correct 752 ms 3300 KB Output is correct
10 Correct 403 ms 3092 KB Output is correct
11 Correct 440 ms 3088 KB Output is correct
12 Correct 446 ms 3000 KB Output is correct
13 Correct 466 ms 2800 KB Output is correct
14 Correct 475 ms 2956 KB Output is correct
15 Correct 558 ms 3060 KB Output is correct
16 Correct 553 ms 3076 KB Output is correct
17 Correct 731 ms 3108 KB Output is correct
18 Correct 683 ms 3096 KB Output is correct
19 Incorrect 653 ms 3140 KB Output isn't correct
20 Halted 0 ms 0 KB -