Submission #1069580

# Submission time Handle Problem Language Result Execution time Memory
1069580 2024-08-22T06:15:32 Z Faisal_Saqib Longest Trip (IOI23_longesttrip) C++17
5 / 100
11 ms 344 KB
#include <bits/stdc++.h>
using namespace std;

#define ll int
#define vll vector<ll>
#define pb push_back
bool are_connected(std::vector<int> A, std::vector<int> B);
std::vector<int> longest_trip(int n, int D)
{
	if(D==3)
	{
		vector<int> ans;
		for(int i=0;i<n;i++)
			ans.push_back(i);
		return ans;
	}
	else if(D==2)
	{
		vector<int> ans;
		for(int i=n-1;i>0;i--)
			ans.pb(i);
		ll s=0;
		vll order={0};
		while(ans.size()>1)
		{
			ll f1=ans.back();
			ans.pop_back();
			ll f2=ans.back();
			ans.pop_back();
			bool r1=are_connected({s},{f1});
			bool r2=are_connected({s},{f2});
			bool r3=are_connected({f1},{f2});
			if(r1 and r3)
			{
				order.pb(f1);
				order.pb(f2);
			}
			else if(r2 and r3)
			{
				order.pb(f2);
				order.pb(f1);
			}
			s=order.back();
		}
		if(ans.size()>0)
		{
			ll l=ans.back();
			bool r1=are_connected({s},{l});
			if(r1)
				order.pb(l);
		}
		return order;
	}
}

Compilation message

longesttrip.cpp: In function 'std::vector<int> longest_trip(int, int)':
longesttrip.cpp:54:1: warning: control reaches end of non-void function [-Wreturn-type]
   54 | }
      | ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Incorrect
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 7 ms 344 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 11 ms 344 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 344 KB Output is correct
2 Correct 8 ms 344 KB Output is correct
3 Correct 8 ms 344 KB Output is correct
4 Correct 8 ms 344 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 344 KB Output is correct
2 Correct 7 ms 344 KB Output is correct
3 Correct 7 ms 344 KB Output is correct
4 Correct 7 ms 344 KB Output is correct
5 Correct 11 ms 344 KB Output is correct
6 Incorrect 0 ms 344 KB Incorrect
7 Halted 0 ms 0 KB -