답안 #942577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
942577 2024-03-10T22:39:57 Z MilosMilutinovic 가장 긴 여행 (IOI23_longesttrip) C++17
45 / 100
808 ms 1368 KB
#include "longesttrip.h"
#include<bits/stdc++.h>

#define pb push_back

using namespace std;

bool con[305][305];

vector<int> longest_trip(int n,int d){
	if(d!=1) return {};
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			con[i][j]=con[j][i]=are_connected({i},{j});
		}
	}
	vector<int> chn1(1,0),chn2;
	for(int i=1;i<n;i++){
		if(!chn1.empty()&&!chn2.empty()){
			bool ok1=false,ok2=false;
			for(int v:chn1) ok1=(ok1|con[v][i]);
			for(int v:chn2) ok2=(ok2|con[v][i]);
			if(ok1&&ok2){
				for(int x=0;x<(int)chn1.size();x++){
					if(con[chn1[x]][i]){
						swap(chn1[x],chn1.back());
						break;
					}
				}
				for(int x=0;x<(int)chn2.size();x++){
					if(con[chn2[x]][i]){
						swap(chn2[x],chn2[0]);
						break;
					}
				}
				chn1.pb(i);
				for(int v:chn2) chn1.pb(v);
				chn2.clear();
				continue;
			}
			if(!ok1) chn2.pb(i);
			if(!ok2) chn1.pb(i);
			continue;
		}	
		bool ok=false;
		for(int v:chn1) if(con[i][v]) ok=true;
		if(!ok){
			chn2={i};
			continue;
		}
		if(con[chn1[0]][i]){
			reverse(chn1.begin(),chn1.end());
			chn1.pb(i);
			continue;
		}
		while(!con[chn1.back()][i]){
			int x=chn1.back();
			chn1.pop_back();
			reverse(chn1.begin(),chn1.end());
			chn1.pb(x);
			reverse(chn1.begin(),chn1.end());
		}
		chn1.pb(i);
	}
	return chn1.size()>chn2.size()?chn1:chn2;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 174 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 19 ms 344 KB Output is correct
3 Correct 115 ms 344 KB Output is correct
4 Correct 308 ms 856 KB Output is correct
5 Correct 703 ms 492 KB Output is correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 25 ms 344 KB Output is correct
8 Correct 122 ms 600 KB Output is correct
9 Correct 234 ms 344 KB Output is correct
10 Correct 730 ms 492 KB Output is correct
11 Correct 779 ms 596 KB Output is correct
12 Correct 748 ms 600 KB Output is correct
13 Correct 720 ms 600 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 11 ms 344 KB Output is correct
16 Correct 35 ms 344 KB Output is correct
17 Correct 67 ms 340 KB Output is correct
18 Correct 129 ms 344 KB Output is correct
19 Correct 263 ms 344 KB Output is correct
20 Correct 254 ms 344 KB Output is correct
21 Correct 720 ms 496 KB Output is correct
22 Correct 742 ms 492 KB Output is correct
23 Correct 683 ms 496 KB Output is correct
24 Correct 668 ms 488 KB Output is correct
25 Correct 9 ms 344 KB Output is correct
26 Correct 8 ms 344 KB Output is correct
27 Correct 20 ms 344 KB Output is correct
28 Correct 21 ms 344 KB Output is correct
29 Correct 19 ms 344 KB Output is correct
30 Correct 155 ms 444 KB Output is correct
31 Correct 158 ms 436 KB Output is correct
32 Correct 173 ms 440 KB Output is correct
33 Correct 280 ms 344 KB Output is correct
34 Correct 266 ms 340 KB Output is correct
35 Correct 230 ms 344 KB Output is correct
36 Correct 754 ms 500 KB Output is correct
37 Correct 786 ms 488 KB Output is correct
38 Correct 731 ms 488 KB Output is correct
39 Correct 808 ms 492 KB Output is correct
40 Correct 764 ms 488 KB Output is correct
41 Correct 646 ms 492 KB Output is correct
42 Correct 741 ms 492 KB Output is correct
43 Correct 688 ms 488 KB Output is correct
44 Correct 718 ms 596 KB Output is correct
45 Correct 8 ms 344 KB Output is correct
46 Correct 8 ms 344 KB Output is correct
47 Correct 21 ms 344 KB Output is correct
48 Correct 21 ms 344 KB Output is correct
49 Correct 21 ms 600 KB Output is correct
50 Correct 148 ms 440 KB Output is correct
51 Correct 159 ms 440 KB Output is correct
52 Correct 160 ms 436 KB Output is correct
53 Correct 262 ms 344 KB Output is correct
54 Correct 264 ms 344 KB Output is correct
55 Correct 255 ms 344 KB Output is correct
56 Correct 776 ms 492 KB Output is correct
57 Correct 728 ms 488 KB Output is correct
58 Correct 732 ms 492 KB Output is correct
59 Correct 727 ms 488 KB Output is correct
60 Correct 688 ms 492 KB Output is correct
61 Correct 773 ms 492 KB Output is correct
62 Correct 729 ms 492 KB Output is correct
63 Correct 647 ms 496 KB Output is correct
64 Correct 679 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 19 ms 344 KB Output is correct
3 Partially correct 116 ms 600 KB Output is partially correct
4 Partially correct 373 ms 344 KB Output is partially correct
5 Partially correct 760 ms 856 KB Output is partially correct
6 Correct 6 ms 344 KB Output is correct
7 Correct 21 ms 344 KB Output is correct
8 Partially correct 128 ms 344 KB Output is partially correct
9 Partially correct 258 ms 344 KB Output is partially correct
10 Partially correct 746 ms 492 KB Output is partially correct
11 Partially correct 708 ms 600 KB Output is partially correct
12 Partially correct 673 ms 492 KB Output is partially correct
13 Partially correct 674 ms 1368 KB Output is partially correct
14 Correct 6 ms 344 KB Output is correct
15 Correct 9 ms 344 KB Output is correct
16 Correct 42 ms 344 KB Output is correct
17 Partially correct 68 ms 344 KB Output is partially correct
18 Partially correct 122 ms 340 KB Output is partially correct
19 Partially correct 262 ms 344 KB Output is partially correct
20 Partially correct 244 ms 344 KB Output is partially correct
21 Correct 8 ms 344 KB Output is correct
22 Correct 8 ms 344 KB Output is correct
23 Correct 25 ms 596 KB Output is correct
24 Correct 20 ms 340 KB Output is correct
25 Correct 22 ms 344 KB Output is correct
26 Partially correct 162 ms 440 KB Output is partially correct
27 Partially correct 161 ms 436 KB Output is partially correct
28 Partially correct 155 ms 440 KB Output is partially correct
29 Partially correct 248 ms 344 KB Output is partially correct
30 Partially correct 223 ms 344 KB Output is partially correct
31 Partially correct 238 ms 344 KB Output is partially correct
32 Correct 12 ms 344 KB Output is correct
33 Correct 10 ms 344 KB Output is correct
34 Correct 23 ms 344 KB Output is correct
35 Correct 24 ms 344 KB Output is correct
36 Correct 20 ms 344 KB Output is correct
37 Partially correct 144 ms 440 KB Output is partially correct
38 Partially correct 156 ms 448 KB Output is partially correct
39 Partially correct 137 ms 444 KB Output is partially correct
40 Partially correct 287 ms 344 KB Output is partially correct
41 Partially correct 255 ms 600 KB Output is partially correct
42 Partially correct 242 ms 344 KB Output is partially correct
43 Partially correct 669 ms 492 KB Output is partially correct
44 Partially correct 744 ms 600 KB Output is partially correct
45 Partially correct 741 ms 496 KB Output is partially correct
46 Partially correct 678 ms 620 KB Output is partially correct
47 Partially correct 733 ms 488 KB Output is partially correct
48 Partially correct 711 ms 496 KB Output is partially correct
49 Partially correct 701 ms 488 KB Output is partially correct
50 Partially correct 719 ms 492 KB Output is partially correct
51 Partially correct 741 ms 600 KB Output is partially correct
52 Partially correct 712 ms 600 KB Output is partially correct
53 Partially correct 676 ms 592 KB Output is partially correct
54 Partially correct 728 ms 488 KB Output is partially correct
55 Partially correct 773 ms 492 KB Output is partially correct
56 Partially correct 713 ms 592 KB Output is partially correct
57 Partially correct 747 ms 492 KB Output is partially correct
58 Partially correct 754 ms 600 KB Output is partially correct
59 Partially correct 769 ms 492 KB Output is partially correct
60 Partially correct 690 ms 496 KB Output is partially correct
61 Partially correct 688 ms 508 KB Output is partially correct
62 Partially correct 706 ms 600 KB Output is partially correct
63 Partially correct 703 ms 492 KB Output is partially correct
64 Partially correct 752 ms 600 KB Output is partially correct
65 Partially correct 735 ms 492 KB Output is partially correct
66 Partially correct 762 ms 492 KB Output is partially correct
67 Partially correct 801 ms 492 KB Output is partially correct
68 Partially correct 709 ms 856 KB Output is partially correct
69 Partially correct 706 ms 492 KB Output is partially correct
70 Partially correct 692 ms 488 KB Output is partially correct
71 Partially correct 772 ms 492 KB Output is partially correct
72 Partially correct 679 ms 492 KB Output is partially correct
73 Partially correct 784 ms 488 KB Output is partially correct
74 Partially correct 724 ms 496 KB Output is partially correct
75 Partially correct 680 ms 492 KB Output is partially correct
76 Partially correct 702 ms 596 KB Output is partially correct
77 Partially correct 709 ms 600 KB Output is partially correct
78 Partially correct 692 ms 596 KB Output is partially correct
79 Partially correct 647 ms 492 KB Output is partially correct
80 Partially correct 694 ms 756 KB Output is partially correct
81 Partially correct 677 ms 492 KB Output is partially correct
82 Partially correct 696 ms 676 KB Output is partially correct