답안 #966502

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966502 2024-04-20T02:06:37 Z Darren0724 즐거운 행로 (APIO20_fun) C++17
47 / 100
101 ms 17792 KB
#include "fun.h"
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
const int N=100005;
int cntid=0;
const int INF=1e9;
vector<int> sz(N,1),pa(N),ans;
priority_queue<pair<int,int>> pq[4];
vector<int> createFunTour(int n, int q) {
	int c1=0;
	int need=(n+1)/2;
	int mn=INF;
	for(int i=0;i<n-1;i++){
		int t=attractionsBehind(0, i);
		if(t>=need&&t<mn){
			mn=t;
			c1=i;
		}
	}
	vector<int> r;
	vector<int> dis0(N,0);
	for(int i=0;i<n;i++){
		dis0[i]=hoursRequired(c1,i);
		if(dis0[i]==1){
			r.push_back(i);
		}
	}
	int rsz=r.size()-1;
	assert(rsz<=2);
	vector<vector<int>> dis(rsz,vector<int>(N));
	vector<int> vis(N);
	for(int i=0;i<rsz;i++){
		for(int j=0;j<n;j++){
			dis[i][j]=hoursRequired(r[i],j);
		}
	}
	for(int i=0;i<n;i++){
		if(i==c1)continue;
		int p=-1;
		for(int j=0;j<rsz;j++){
			if(dis[j][i]<dis0[i]){
				p=j;break;
			}
		}
		if(p==-1)p=rsz;
		pq[p].push({dis0[i],i});
	}
	cntid=4;
	int last=-1;
	int left=n-1;
	for(int i=1;i<n;i++){
		array<int,3> p={-1,-1,-1};
		for(int j=0;j<cntid;j++){
			if(j==last||pq[j].size()==0)continue;
			p=max(p,array<int,3>{pq[j].top().first,0,j});
		}
		pair<int,int> mx={-1,-1};
		for(int j=0;j<cntid;j++){
			mx=max(mx,{(int)pq[j].size(),j});
		}
		if((left)/2<mx.first){
			assert(last!=mx.second);
			p[2]=mx.second;
		}
		last=p[2];
		assert(last!=-1&&pq[last].size()>0);
		auto [dis1,idx]=pq[last].top();
		pq[last].pop();
		ans.push_back(idx);
		left--;
	}
	ans.push_back(c1);
	/*for(int j:ans){
		cout<<j<<' ';
	}
	cout<<endl;*/
  	return ans;
}
/*
46 100000
0 1
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
0 16
16 17 
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
0 31
31 32
31 33
32 34
32 35
33 36
33 37
34 38
34 39
35 40
35 41
36 42 
36 43
37 44
37 45
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2768 KB Output is correct
2 Correct 1 ms 2004 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2752 KB Output is correct
6 Correct 1 ms 3024 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2772 KB Output is correct
9 Correct 1 ms 2768 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2772 KB Output is correct
12 Correct 1 ms 2772 KB Output is correct
13 Correct 1 ms 2364 KB Output is correct
14 Correct 1 ms 2772 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 2 ms 2772 KB Output is correct
17 Correct 1 ms 2772 KB Output is correct
18 Correct 1 ms 2772 KB Output is correct
19 Correct 2 ms 2772 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2768 KB Output is correct
2 Correct 1 ms 2004 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2752 KB Output is correct
6 Correct 1 ms 3024 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2772 KB Output is correct
9 Correct 1 ms 2768 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2772 KB Output is correct
12 Correct 1 ms 2772 KB Output is correct
13 Correct 1 ms 2364 KB Output is correct
14 Correct 1 ms 2772 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 2 ms 2772 KB Output is correct
17 Correct 1 ms 2772 KB Output is correct
18 Correct 1 ms 2772 KB Output is correct
19 Correct 2 ms 2772 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2772 KB Output is correct
22 Correct 1 ms 2768 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 2 ms 2772 KB Output is correct
25 Correct 1 ms 2968 KB Output is correct
26 Correct 1 ms 2772 KB Output is correct
27 Correct 1 ms 2772 KB Output is correct
28 Correct 1 ms 2772 KB Output is correct
29 Correct 2 ms 2760 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 2 ms 2772 KB Output is correct
32 Correct 2 ms 2772 KB Output is correct
33 Correct 1 ms 2772 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 2 ms 2772 KB Output is correct
36 Correct 2 ms 2772 KB Output is correct
37 Correct 2 ms 2772 KB Output is correct
38 Correct 2 ms 2772 KB Output is correct
39 Correct 2 ms 2772 KB Output is correct
40 Correct 2 ms 2772 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2004 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 2 ms 2752 KB Output is correct
5 Correct 1 ms 3024 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2772 KB Output is correct
8 Correct 1 ms 2768 KB Output is correct
9 Correct 1 ms 2772 KB Output is correct
10 Correct 1 ms 2768 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
13 Correct 1 ms 2968 KB Output is correct
14 Correct 1 ms 2772 KB Output is correct
15 Correct 1 ms 2772 KB Output is correct
16 Correct 2 ms 2768 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 101 ms 17792 KB Output is correct
19 Correct 2 ms 2768 KB Output is correct
20 Correct 3 ms 3024 KB Output is correct
21 Correct 4 ms 3028 KB Output is correct
22 Correct 6 ms 3540 KB Output is correct
23 Correct 11 ms 4816 KB Output is correct
24 Correct 14 ms 5332 KB Output is correct
25 Correct 64 ms 11472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2004 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2772 KB Output is correct
5 Correct 1 ms 2772 KB Output is correct
6 Correct 1 ms 2364 KB Output is correct
7 Correct 1 ms 2772 KB Output is correct
8 Correct 2 ms 2760 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 1 ms 2772 KB Output is correct
13 Incorrect 2 ms 3024 KB Tour is not fun
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2768 KB Output is correct
2 Correct 1 ms 2004 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2752 KB Output is correct
6 Correct 1 ms 3024 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2772 KB Output is correct
9 Correct 1 ms 2768 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2772 KB Output is correct
12 Correct 1 ms 2772 KB Output is correct
13 Correct 1 ms 2364 KB Output is correct
14 Correct 1 ms 2772 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 2 ms 2772 KB Output is correct
17 Correct 1 ms 2772 KB Output is correct
18 Correct 1 ms 2772 KB Output is correct
19 Correct 2 ms 2772 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2772 KB Output is correct
22 Correct 1 ms 2768 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 2 ms 2772 KB Output is correct
25 Correct 1 ms 2968 KB Output is correct
26 Correct 1 ms 2772 KB Output is correct
27 Correct 1 ms 2772 KB Output is correct
28 Correct 1 ms 2772 KB Output is correct
29 Correct 2 ms 2760 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 2 ms 2772 KB Output is correct
32 Correct 2 ms 2772 KB Output is correct
33 Correct 1 ms 2772 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 2 ms 2772 KB Output is correct
36 Correct 2 ms 2772 KB Output is correct
37 Correct 2 ms 2772 KB Output is correct
38 Correct 2 ms 2772 KB Output is correct
39 Correct 2 ms 2772 KB Output is correct
40 Correct 2 ms 2772 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 2 ms 2768 KB Output is correct
43 Correct 1 ms 2396 KB Output is correct
44 Correct 101 ms 17792 KB Output is correct
45 Correct 2 ms 2768 KB Output is correct
46 Correct 3 ms 3024 KB Output is correct
47 Correct 4 ms 3028 KB Output is correct
48 Correct 6 ms 3540 KB Output is correct
49 Correct 11 ms 4816 KB Output is correct
50 Correct 14 ms 5332 KB Output is correct
51 Correct 64 ms 11472 KB Output is correct
52 Incorrect 2 ms 3024 KB Tour is not fun
53 Halted 0 ms 0 KB -