Submission #1109676

# Submission time Handle Problem Language Result Execution time Memory
1109676 2024-11-07T09:29:55 Z jerzyk Longest Trip (IOI23_longesttrip) C++17
100 / 100
40 ms 848 KB
#include <bits/stdc++.h>
#include "longesttrip.h"

using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const int II = 2 * 1000 * 1000 * 1000;
const int N = 1000 * 1000 + 7;

bool SQ(int a, int b)
{
	vector<int> v1 = {a}, v2 = {b};
	return are_connected(v1, v2);
}

void J(vector<int> &a, vector<int> &b)
{
	for(int i = 0; i < (int)b.size(); ++i)
		a.pb(b[i]);
	b.clear();
}

void R(vector<int> &a, int r)
{
	vector<int> nw;
	for(int i = r; i < (int)a.size(); ++i)
		nw.pb(a[i]);
	for(int i = 0; i < r; ++i)
		nw.pb(a[i]);
	a = nw;
}

void Merge(vector<int> &a, vector<int> &b, bool xd)
{
	if(!xd && SQ(a.back(), b.back()))
	{
		reverse(b.begin(), b.end());
		J(a, b);
		return;
	}
	if(SQ(a.back(), b[0]))
	{
		J(a, b);
		return;
	}
	if(SQ(a[0], b.back()))
	{
		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());
		J(a, b);
		return;
	}

	int p, s, k;
	vector<int> q1, qd;
	p = 0, k = (int)a.size();
	while(p < k)
	{
		s = (p + k) / 2;
		q1.clear();
		for(int i = 0; i <= s; ++i)
			q1.pb(a[i]);
		if(are_connected(q1, b))
			k = s;
		else
			p = s + 1;
	}
	if(p == (int)a.size()) return;

	R(a, p);
	qd = {a[0]};
	p = 0, k = (int)b.size();
	while(p < k)
	{
		s = (p + k) / 2;
		q1.clear();
		for(int i = 0; i <= s; ++i)
			q1.pb(b[i]);
		if(are_connected(q1, qd))
			k = s;
		else
			p = s + 1;
	}
	R(b, p);
	reverse(a.begin(), a.end());
	J(a, b);
}

vector<int> longest_trip(int _N, int _X_D)
{
	int n = _N;
	vector<int> l1, l2;
	bool xd = true;
	l1.pb(0);

	for(int i = 1; i < n; ++i)
	{
		if(l1.size() < l2.size()) swap(l1, l2);

		if(SQ(i, l1.back()))
		{
			l1.pb(i);
			if(l2.size() != 0) xd = false;
			continue;
		}
		if(xd || SQ(i, l2.back()))
		{
			l2.pb(i);
			xd = true;
			continue;
		}
		reverse(l2.begin(), l2.end());
		if((int)l2.size() > 0) xd = false;
		else xd = true;
		J(l1, l2);
		l2.pb(i);
	}
	if(n == 1) return l1;

	
	if(l1.size() < l2.size())
		swap(l1, l2);
	if(l2.size() == 0)
		return l1;
	Merge(l1, l2, xd);
	return l1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 5 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 336 KB Output is correct
2 Correct 16 ms 336 KB Output is correct
3 Correct 17 ms 336 KB Output is correct
4 Correct 15 ms 336 KB Output is correct
5 Correct 16 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 500 KB Output is correct
2 Correct 15 ms 336 KB Output is correct
3 Correct 17 ms 504 KB Output is correct
4 Correct 17 ms 336 KB Output is correct
5 Correct 17 ms 336 KB Output is correct
6 Correct 23 ms 336 KB Output is correct
7 Correct 18 ms 336 KB Output is correct
8 Correct 17 ms 336 KB Output is correct
9 Correct 13 ms 336 KB Output is correct
10 Correct 14 ms 336 KB Output is correct
11 Correct 23 ms 336 KB Output is correct
12 Correct 13 ms 336 KB Output is correct
13 Correct 18 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 336 KB Output is correct
2 Correct 15 ms 336 KB Output is correct
3 Correct 18 ms 336 KB Output is correct
4 Correct 18 ms 336 KB Output is correct
5 Correct 17 ms 336 KB Output is correct
6 Correct 21 ms 336 KB Output is correct
7 Correct 20 ms 336 KB Output is correct
8 Correct 16 ms 336 KB Output is correct
9 Correct 17 ms 336 KB Output is correct
10 Correct 17 ms 336 KB Output is correct
11 Correct 15 ms 592 KB Output is correct
12 Correct 16 ms 336 KB Output is correct
13 Correct 15 ms 336 KB Output is correct
14 Correct 28 ms 336 KB Output is correct
15 Correct 29 ms 336 KB Output is correct
16 Correct 18 ms 336 KB Output is correct
17 Correct 20 ms 336 KB Output is correct
18 Correct 20 ms 336 KB Output is correct
19 Correct 15 ms 336 KB Output is correct
20 Correct 16 ms 336 KB Output is correct
21 Correct 16 ms 336 KB Output is correct
22 Correct 22 ms 504 KB Output is correct
23 Correct 21 ms 336 KB Output is correct
24 Correct 19 ms 336 KB Output is correct
25 Correct 32 ms 336 KB Output is correct
26 Correct 32 ms 336 KB Output is correct
27 Correct 31 ms 336 KB Output is correct
28 Correct 26 ms 336 KB Output is correct
29 Correct 25 ms 336 KB Output is correct
30 Correct 19 ms 336 KB Output is correct
31 Correct 23 ms 336 KB Output is correct
32 Correct 26 ms 336 KB Output is correct
33 Correct 19 ms 508 KB Output is correct
34 Correct 18 ms 336 KB Output is correct
35 Correct 23 ms 336 KB Output is correct
36 Correct 17 ms 336 KB Output is correct
37 Correct 18 ms 336 KB Output is correct
38 Correct 24 ms 616 KB Output is correct
39 Correct 22 ms 440 KB Output is correct
40 Correct 21 ms 504 KB Output is correct
41 Correct 24 ms 336 KB Output is correct
42 Correct 25 ms 336 KB Output is correct
43 Correct 17 ms 592 KB Output is correct
44 Correct 25 ms 336 KB Output is correct
45 Correct 28 ms 336 KB Output is correct
46 Correct 21 ms 336 KB Output is correct
47 Correct 25 ms 336 KB Output is correct
48 Correct 37 ms 336 KB Output is correct
49 Correct 28 ms 336 KB Output is correct
50 Correct 21 ms 336 KB Output is correct
51 Correct 22 ms 336 KB Output is correct
52 Correct 27 ms 336 KB Output is correct
53 Correct 17 ms 336 KB Output is correct
54 Correct 16 ms 336 KB Output is correct
55 Correct 24 ms 336 KB Output is correct
56 Correct 17 ms 444 KB Output is correct
57 Correct 19 ms 440 KB Output is correct
58 Correct 16 ms 336 KB Output is correct
59 Correct 27 ms 848 KB Output is correct
60 Correct 22 ms 696 KB Output is correct
61 Correct 24 ms 336 KB Output is correct
62 Correct 16 ms 336 KB Output is correct
63 Correct 21 ms 336 KB Output is correct
64 Correct 22 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 336 KB Output is correct
2 Correct 19 ms 504 KB Output is correct
3 Correct 13 ms 336 KB Output is correct
4 Correct 17 ms 336 KB Output is correct
5 Correct 22 ms 336 KB Output is correct
6 Correct 19 ms 336 KB Output is correct
7 Correct 19 ms 508 KB Output is correct
8 Correct 16 ms 336 KB Output is correct
9 Correct 19 ms 336 KB Output is correct
10 Correct 15 ms 336 KB Output is correct
11 Correct 19 ms 336 KB Output is correct
12 Correct 14 ms 336 KB Output is correct
13 Correct 21 ms 336 KB Output is correct
14 Correct 40 ms 336 KB Output is correct
15 Correct 24 ms 336 KB Output is correct
16 Correct 23 ms 504 KB Output is correct
17 Correct 21 ms 336 KB Output is correct
18 Correct 21 ms 336 KB Output is correct
19 Correct 22 ms 336 KB Output is correct
20 Correct 19 ms 336 KB Output is correct
21 Correct 35 ms 336 KB Output is correct
22 Correct 29 ms 336 KB Output is correct
23 Correct 27 ms 336 KB Output is correct
24 Correct 24 ms 336 KB Output is correct
25 Correct 22 ms 336 KB Output is correct
26 Correct 21 ms 336 KB Output is correct
27 Correct 23 ms 336 KB Output is correct
28 Correct 22 ms 336 KB Output is correct
29 Correct 15 ms 444 KB Output is correct
30 Correct 20 ms 508 KB Output is correct
31 Correct 18 ms 592 KB Output is correct
32 Correct 21 ms 336 KB Output is correct
33 Correct 22 ms 336 KB Output is correct
34 Correct 22 ms 336 KB Output is correct
35 Correct 25 ms 336 KB Output is correct
36 Correct 32 ms 336 KB Output is correct
37 Correct 15 ms 592 KB Output is correct
38 Correct 24 ms 336 KB Output is correct
39 Correct 24 ms 336 KB Output is correct
40 Correct 24 ms 336 KB Output is correct
41 Correct 21 ms 436 KB Output is correct
42 Correct 17 ms 336 KB Output is correct
43 Correct 15 ms 336 KB Output is correct
44 Correct 21 ms 336 KB Output is correct
45 Correct 15 ms 512 KB Output is correct
46 Correct 17 ms 336 KB Output is correct
47 Correct 22 ms 336 KB Output is correct
48 Correct 18 ms 336 KB Output is correct
49 Correct 25 ms 436 KB Output is correct
50 Correct 22 ms 592 KB Output is correct
51 Correct 23 ms 336 KB Output is correct
52 Correct 25 ms 336 KB Output is correct
53 Correct 16 ms 336 KB Output is correct
54 Correct 23 ms 504 KB Output is correct
55 Correct 24 ms 336 KB Output is correct
56 Correct 19 ms 444 KB Output is correct
57 Correct 21 ms 336 KB Output is correct
58 Correct 24 ms 504 KB Output is correct
59 Correct 19 ms 336 KB Output is correct
60 Correct 23 ms 336 KB Output is correct
61 Correct 22 ms 336 KB Output is correct
62 Correct 13 ms 336 KB Output is correct
63 Correct 16 ms 336 KB Output is correct
64 Correct 21 ms 336 KB Output is correct
65 Correct 24 ms 436 KB Output is correct
66 Correct 27 ms 592 KB Output is correct
67 Correct 20 ms 336 KB Output is correct
68 Correct 26 ms 592 KB Output is correct
69 Correct 26 ms 592 KB Output is correct
70 Correct 21 ms 336 KB Output is correct
71 Correct 19 ms 696 KB Output is correct
72 Correct 22 ms 448 KB Output is correct
73 Correct 19 ms 592 KB Output is correct
74 Correct 27 ms 592 KB Output is correct
75 Correct 24 ms 336 KB Output is correct
76 Correct 25 ms 504 KB Output is correct
77 Correct 17 ms 444 KB Output is correct
78 Correct 23 ms 336 KB Output is correct
79 Correct 17 ms 336 KB Output is correct
80 Correct 21 ms 444 KB Output is correct
81 Correct 22 ms 336 KB Output is correct
82 Correct 23 ms 336 KB Output is correct