Submission #1069721

# Submission time Handle Problem Language Result Execution time Memory
1069721 2024-08-22T08:30:58 Z UmairAhmadMirza Longest Trip (IOI23_longesttrip) C++17
40 / 100
991 ms 600 KB
#include <bits/stdc++.h>
using namespace std;

bool are_connected(vector<int> A, vector<int> B);

int const MAXN=260;
bool con[MAXN][MAXN];
vector<int> path,longest;
bool vis[MAXN];
int nn;
void dfs(int node){
	path.push_back(node);
	if(path.size()>longest.size())
		longest=path;
	vis[node]=1;
	for(int i=0;i<nn;i++)
		if(vis[i]==0 && con[node][i])
			dfs(i);
	path.pop_back();
}
vector<int> longest_trip(int n, int D){
	longest.clear();
	nn=n;
	vector<int> a,b;
	for(int i=0;i<n;i++){
		a.push_back(i);
		for(int j=i+1;j<n;j++){
			b.push_back(j);
			con[i][j]=con[j][i]=are_connected(a,b);
			b.pop_back();
		}
		a.pop_back();
	}
	if(D>1){
		path.clear();
		for (int i = 0; i < n; ++i)
			path.push_back(i);
		bool bl=0;
		for(int i=0;i<n-1;i++)
			if(con[path[i]][path[i+1]]==0){
				if(i==n-2)
					rotate(path.rbegin(), path.rbegin() + 1, path.rend());
				else
					swap(path[i+1],path[i+2]);
			}
		return path;
	}
	for (int i = 0; i < n; ++i)
	{
		path.clear();
		for(int j=0;j<n;j++)
			vis[j]=0;
		dfs(i);
	}
	return longest;
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:38:8: warning: unused variable 'bl' [-Wunused-variable]
   38 |   bool bl=0;
      |        ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 203 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 150 ms 344 KB Output is correct
4 Correct 416 ms 344 KB Output is correct
5 Correct 870 ms 476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 160 ms 344 KB Output is correct
4 Correct 422 ms 344 KB Output is correct
5 Correct 815 ms 500 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 24 ms 344 KB Output is correct
8 Correct 143 ms 344 KB Output is correct
9 Correct 327 ms 344 KB Output is correct
10 Correct 808 ms 596 KB Output is correct
11 Correct 885 ms 484 KB Output is correct
12 Correct 835 ms 476 KB Output is correct
13 Correct 822 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Correct 135 ms 344 KB Output is correct
4 Correct 429 ms 468 KB Output is correct
5 Correct 931 ms 484 KB Output is correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 22 ms 344 KB Output is correct
8 Correct 122 ms 344 KB Output is correct
9 Correct 329 ms 592 KB Output is correct
10 Correct 916 ms 480 KB Output is correct
11 Correct 930 ms 484 KB Output is correct
12 Correct 943 ms 480 KB Output is correct
13 Correct 960 ms 484 KB Output is correct
14 Correct 7 ms 344 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Correct 34 ms 344 KB Output is correct
17 Correct 114 ms 344 KB Output is correct
18 Correct 145 ms 344 KB Output is correct
19 Correct 349 ms 592 KB Output is correct
20 Correct 349 ms 440 KB Output is correct
21 Correct 894 ms 496 KB Output is correct
22 Correct 991 ms 480 KB Output is correct
23 Correct 988 ms 480 KB Output is correct
24 Correct 915 ms 596 KB Output is correct
25 Correct 6 ms 344 KB Output is correct
26 Correct 12 ms 344 KB Output is correct
27 Correct 21 ms 344 KB Output is correct
28 Correct 22 ms 344 KB Output is correct
29 Correct 23 ms 344 KB Output is correct
30 Correct 200 ms 460 KB Output is correct
31 Correct 205 ms 344 KB Output is correct
32 Correct 227 ms 344 KB Output is correct
33 Correct 312 ms 344 KB Output is correct
34 Correct 336 ms 344 KB Output is correct
35 Correct 304 ms 344 KB Output is correct
36 Correct 910 ms 496 KB Output is correct
37 Correct 938 ms 592 KB Output is correct
38 Correct 985 ms 476 KB Output is correct
39 Correct 872 ms 476 KB Output is correct
40 Correct 850 ms 480 KB Output is correct
41 Correct 745 ms 484 KB Output is correct
42 Correct 833 ms 492 KB Output is correct
43 Correct 904 ms 476 KB Output is correct
44 Correct 894 ms 480 KB Output is correct
45 Correct 6 ms 344 KB Output is correct
46 Correct 9 ms 344 KB Output is correct
47 Correct 20 ms 344 KB Output is correct
48 Correct 32 ms 344 KB Output is correct
49 Correct 22 ms 344 KB Output is correct
50 Correct 211 ms 344 KB Output is correct
51 Correct 198 ms 344 KB Output is correct
52 Correct 212 ms 344 KB Output is correct
53 Correct 318 ms 444 KB Output is correct
54 Correct 312 ms 448 KB Output is correct
55 Correct 306 ms 344 KB Output is correct
56 Correct 977 ms 476 KB Output is correct
57 Correct 963 ms 484 KB Output is correct
58 Correct 920 ms 548 KB Output is correct
59 Correct 938 ms 476 KB Output is correct
60 Correct 866 ms 484 KB Output is correct
61 Correct 935 ms 524 KB Output is correct
62 Correct 891 ms 488 KB Output is correct
63 Correct 959 ms 476 KB Output is correct
64 Correct 922 ms 484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 22 ms 344 KB Output is correct
3 Partially correct 154 ms 344 KB Output is partially correct
4 Partially correct 434 ms 452 KB Output is partially correct
5 Partially correct 831 ms 480 KB Output is partially correct
6 Correct 7 ms 344 KB Output is correct
7 Correct 29 ms 344 KB Output is correct
8 Partially correct 150 ms 452 KB Output is partially correct
9 Partially correct 328 ms 600 KB Output is partially correct
10 Partially correct 898 ms 592 KB Output is partially correct
11 Partially correct 949 ms 492 KB Output is partially correct
12 Partially correct 899 ms 600 KB Output is partially correct
13 Partially correct 874 ms 484 KB Output is partially correct
14 Correct 4 ms 344 KB Output is correct
15 Correct 10 ms 344 KB Output is correct
16 Incorrect 6 ms 344 KB Incorrect
17 Halted 0 ms 0 KB -