QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#293404#7119. Longest Tripdanielkou58555 8ms4164kbC++174.6kb2023-12-29 06:48:152024-04-28 09:19:53

Judging History

你现在查看的是最新测评结果

  • [2024-04-28 09:19:53]
  • 管理员手动重测本题所有提交记录
  • 测评结果:5
  • 用时:8ms
  • 内存:4164kb
  • [2023-12-29 06:48:16]
  • 评测
  • 测评结果:5
  • 用时:10ms
  • 内存:3832kb
  • [2023-12-29 06:48:15]
  • 提交

answer

// Source: https://usaco.guide/general/io

#include "longesttrip.h"
#include <bits/stdc++.h>

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()

using namespace std;

map<pair<vector<int>, vector<int>>, bool> dp;

bool connected(vector<int> a, vector<int> b) {
	if (!dp.count({a, b})) {
		dp[{a, b}] = are_connected(a, b);
	}

	return dp[{a, b}];
}

vector<int> longest_trip(int N, int D) {
	dp.clear();

	vector<int> chain1, chain2, chain3;

	vector<int> a, b, newa, newb;

	vector<int> trust;

	for (int i = 0; i < N; i++) {
		trust.push_back(i);
	}

	// mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
	// shuffle(trust.begin(), trust.end(), rng);

	random_shuffle(all(trust));

	chain1.push_back(trust[0]), chain2.push_back(trust[1]);

	for (int i = 2; i + 1 < N; i += 2) {
		a.clear(); a.push_back(chain1.back());
		b.clear(); b.push_back(chain2.back());
		newa.clear(); newa.push_back(trust[i]);
		newb.clear(); newb.push_back(trust[i + 1]);

		if (connected(newa, newb)) {
			if (connected(a, newa)) {
				chain1.push_back(newa.back()); chain1.push_back(newb.back());
			} else if (connected(b, newa)) {
				chain2.push_back(newa.back()); chain2.push_back(newb.back());
			} else {
				for (int i = sz(chain2) - 1; i >= 0; i--) {
					chain1.push_back(chain2[i]);
				}

				chain2.clear(); chain2.push_back(newa[0]), chain2.push_back(newb[0]);
			}
		} else if (connected(a, newa)) {
			chain1.push_back(newa[0]);

			if (connected(b, newa)) {
				for (int i = sz(chain2) - 1; i >= 0; i--) {
					chain1.push_back(chain2[i]);
				}

				chain2.clear(); chain2.push_back(newb[0]);
			} else {
				chain2.push_back(newb[0]);
			}
		} else {
			chain1.push_back(newb[0]);

			if (connected(b, newb)) {
				for(int i = sz(chain2) - 1; i >= 0; i--) {
					chain1.push_back(chain2[i]);
				}

				chain2.clear(); chain2.push_back(newa[0]);
			} else {
				chain2.push_back(newa[0]);
			}
		}
	}

	if (N % 2) {
		a.clear(); a.push_back(chain1.back());
		b.clear(); b.push_back(chain2.back());
		newa.clear(); newa.push_back(trust[N - 1]);

		if (connected(a, newa)) {
			chain1.push_back(newa[0]);
		} else if (connected(b, newa)) {
			chain2.push_back(newa[0]);
		} else {
			for (int i = sz(chain2) - 1; i >= 0; i--) {
				chain1.push_back(chain2[i]);
			}

			chain2.clear(); chain2.push_back(newa[0]);
		}
	}

	if (!connected(chain1, chain2)) {
		if (sz(chain1) > sz(chain2)) {
			return chain1;
		} else {
			return chain2;
		}
	}

	a.clear(); a.push_back(chain1.back());
	b.clear(); b.push_back(chain2.back());

	if (connected(a, b)) {
		// entire thing
		for (int i = 0; i < sz(chain2); i++) {
			chain1.push_back(chain2[i]);
		}

		return chain1;
	}

	a.clear(); a.push_back(chain1.back());
	b.clear(); b.push_back(chain2[0]);

	if (connected(a, b)) {
		for (int i : chain2) {
			chain1.push_back(i);
		}

		return chain1;
	}

	a.clear(), a.push_back(chain1[0]);
	b.clear(), b.push_back(chain2.back());

	if (connected(a, b)) {
		for (int i : chain1) {
			chain2.push_back(i);
		}
		
		return chain2;
	}

	// I FUCKING HATE THESE PROBLEMS ADSLKFJALSDKJFSHDJI''DS;INUOSJOERFEEWFAJNEIJ9IIQ2IW2O-p-12323948893vn [WUR89R1KJASHILUA EIFJFLJKJKDKLKKLJ;KL;KL;LKKL;J]
	a.clear(), a.push_back(chain1[0]);
	b.clear(), b.push_back(chain2[0]);

	if(connected(a, b)) {
		chain3.clear();

		for (int i = sz(chain1) - 1; i >= 0; i--) {
			chain3.push_back(chain1[i]);
		}

		for (int i = 0; i < sz(chain2); i++) {
			chain3.push_back(chain2[i]);
		}

		return chain3;
	}

	int l = 0, r = sz(chain2);

	while (l < r) {
		int m = l + (r - l) / 2;

		if (l == m) {
			break;
		}

		chain3.clear();

		for (int i = l; i < m; i++) {
			chain3.push_back(chain2[i]);
		}

		if (sz(chain3) && connected(chain1, chain2)) {
			r = m;
		} else {
			l = m;
		}
	}

	int fuck = r - 1;
	l = 0, r = sz(chain1);
	b.clear(), b.push_back(chain2[fuck]);
	int last_mid = l + (r - l) / 2;
	while (l < r) {
		int m = l + (r - l) / 2; last_mid = m;

		if (l == m) {
			break;
		}

		chain3.clear();

		for (int i = l; i < m; i++) {
			chain3.push_back(chain1[i]);
		}

		if (sz(chain3) > 0 && connected(b, chain3)) {
			r = m;
		} else {
			l = m;
		}
	}

	a.clear(), a.push_back(chain1[last_mid]);
	chain3.clear();

	for (int i = r; i < sz(chain1); i++) {
		chain3.push_back(chain1[i]);
	}

	for (int i = 0; i < r; i++) {
		chain3.push_back(chain1[i]);
	}

	for (int i = fuck; i < sz(chain2); i++) {
		chain3.push_back(chain2[i]);
	}

	for (int i = 0; i < fuck; i++) {
		chain3.push_back(chain2[i]);
	}

	return chain3;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 5ms
memory: 4100kb

input:

341
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
1
1
3 3
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 2 1 0 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
1 3 0 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 2 1 0 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1...

result:

ok 

Test #2:

score: 0
Accepted
time: 5ms
memory: 3852kb

input:

103
10 3
1
1
1
1
1
1
1
1
1
1
1
10 3
1
1
1
1
1
1
1
1
1
1
1
10 3
1
1
1
1
1
1
1
1
1
1
1
10 3
1
1
1
1
1
1
1
1
1
1
1
10 3
1
1
1
1
1
1
1
1
1
1
1
10 3
1
1
1
1
1
1
1
1
1
1
1
10 3
1
1
1
1
1
1
1
1
1
1
1
10 3
1
1
1
1
1
1
1
1
1
1
1
10 3
1
1
1
1
1
1
1
1
1
1
1
10 3
1
1
1
1
1
1
1
1
1
1
1
10 3
1
1
1
1
1
1
1
1
1
1
1...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 7 8
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 4 7
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 5
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 8 0
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 2 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 5 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 6 9...

result:

ok 

Test #3:

score: 0
Accepted
time: 5ms
memory: 3828kb

input:

22
50 3
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
50 3
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
50 3
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 11 15
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 4 11
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 24 35
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 15 24
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 17 36
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 35 17
3kC2Ia2048BfyJVGojMUKKtilctlZKc...

result:

ok 

Test #4:

score: 0
Accepted
time: 5ms
memory: 3780kb

input:

8
128 3
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
128 3
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 11 69
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 110 11
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 119 35
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 69 119
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 17 109
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 35 17
3kC2Ia2048BfyJVGojMUKKtilc...

result:

ok 

Test #5:

score: 0
Accepted
time: 0ms
memory: 4148kb

input:

4
256 3
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 11 69
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 110 11
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 209 142
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 69 209
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 17 109
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 142 17
3kC2Ia2048BfyJVGojMUKKti...

result:

ok 

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 10
Accepted
time: 2ms
memory: 4120kb

input:

341
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 2 1 0 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
1 3 0 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 2 1 0 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1...

result:

ok 

Test #7:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

103
10 2
1
1
1
1
1
1
1
1
1
1
1
10 2
1
1
1
1
1
1
1
1
1
1
1
10 2
1
1
1
1
1
1
1
1
1
1
1
10 2
1
1
1
1
1
1
1
1
1
1
1
10 2
1
1
1
1
1
1
1
1
1
1
1
10 2
1
1
1
1
1
1
1
1
1
1
1
10 2
1
1
1
1
1
1
1
1
1
1
1
10 2
1
1
1
1
1
1
1
1
1
1
1
10 2
1
1
1
1
1
1
1
1
1
1
1
10 2
1
1
1
1
1
1
1
1
1
1
1
10 2
1
1
1
1
1
1
1
1
1
1
1...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 7 8
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 4 7
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 5
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 8 0
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 2 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 5 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 6 9...

result:

ok 

Test #8:

score: 0
Accepted
time: 5ms
memory: 3904kb

input:

22
50 2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
50 2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
50 2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 11 15
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 4 11
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 24 35
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 15 24
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 17 36
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 35 17
3kC2Ia2048BfyJVGojMUKKtilctlZKc...

result:

ok 

Test #9:

score: 0
Accepted
time: 0ms
memory: 3924kb

input:

8
128 2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
128 2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 11 69
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 110 11
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 119 35
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 69 119
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 17 109
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 35 17
3kC2Ia2048BfyJVGojMUKKtilc...

result:

ok 

Test #10:

score: 0
Accepted
time: 3ms
memory: 3936kb

input:

4
256 2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 11 69
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 110 11
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 209 142
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 69 209
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 17 109
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 142 17
3kC2Ia2048BfyJVGojMUKKti...

result:

ok 

Test #11:

score: 0
Accepted
time: 3ms
memory: 4120kb

input:

341
3 2
1
1
0
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
1
1
3 2
1
1
0
1
1
3 2
1
1
0
1
1
3 2
1
1
0
1
1
3 2
0
1
1
1
1
3 2
1
1
0
1
1
3 2
1
1
0
1
1
3 2
1
1
1
1
3 2
0
1
1
1
1
3 2
0
1
1
1
1
3 2
0
1
1
1
1
3 2
1
1
1
1
3 2
0
1
1
1
1
3 2
1
1
0
1
1
3 2
0
1
1
1
1
3 2
0
1
1
1
1
3 2
1
1
1
1
3 2
1
1
0
1
1
3 2
0
1
1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 2 1 0 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
1 3 2 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 2 1 0...

result:

ok 

Test #12:

score: -10
Wrong Answer
time: 1ms
memory: 4104kb

input:

103
10 2
1
1
1
1
1
1
1
1
1
1
1
10 2
0
1
1
1
1
1
1
1
1
1
1
1
10 2
0
1
1
1
1
1
1
1
1
1
1
1
10 2
1
1
1
1
1
1
1
0
1
1
1
1
10 2
1
1
1
1
0
1
1
1
1
1
1
1
10 2
1
0
1
1
1
1
1
1
1
1
1

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 7 8
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 4 7
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 5
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 8 0
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 2 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 5 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 6 9...

result:

wrong answer 

Subtask #3:

score: 0
Wrong Answer

Test #19:

score: 25
Accepted
time: 5ms
memory: 3808kb

input:

341
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 2 1 0 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
1 3 0 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 2 1 0 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1...

result:

ok 

Test #20:

score: 0
Accepted
time: 0ms
memory: 3792kb

input:

103
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 7 8
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 4 7
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 5
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 8 0
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 2 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 5 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 6 9...

result:

ok 

Test #21:

score: 0
Accepted
time: 8ms
memory: 3832kb

input:

22
50 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
50 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
50 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 11 15
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 4 11
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 24 35
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 15 24
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 17 36
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 35 17
3kC2Ia2048BfyJVGojMUKKtilctlZKc...

result:

ok 

Test #22:

score: 0
Accepted
time: 5ms
memory: 3840kb

input:

8
128 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
128 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 11 69
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 110 11
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 119 35
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 69 119
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 17 109
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 35 17
3kC2Ia2048BfyJVGojMUKKtilc...

result:

ok 

Test #23:

score: 0
Accepted
time: 0ms
memory: 3936kb

input:

4
256 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 11 69
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 110 11
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 209 142
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 69 209
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 17 109
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 142 17
3kC2Ia2048BfyJVGojMUKKti...

result:

ok 

Test #24:

score: 0
Accepted
time: 0ms
memory: 3880kb

input:

341
3 1
1
1
0
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
0
1
1
3 1
1
1
0
1
1
3 1
1
1
0
1
1
3 1
0
1
1
1
1
3 1
1
1
0
1
1
3 1
1
1
0
1
1
3 1
1
1
1
1
3 1
0
1
1
1
1
3 1
0
1
1
1
1
3 1
0
1
1
1
1
3 1
1
1
1
1
3 1
0
1
1
1
1
3 1
1
1
0
1
1
3 1
0
1
1
1
1
3 1
0
1
1
1
1
3 1
1
1
1
1
3 1
1
1
0
1
1
3 1
0
1
1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 2 1 0 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
1 3 2 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 2 1 0...

result:

ok 

Test #25:

score: -25
Wrong Answer
time: 0ms
memory: 3764kb

input:

103
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
0
1
1
1
1
1
1
1
1
1
1
1
10 1
0
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
0
1
1
1
1
10 1
1
1
1
1
0
1
1
1
1
1
1
1
10 1
1
0
1
1
1
1
1
1
1
1
1

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 7 8
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 4 7
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 5
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 8 0
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 2 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 5 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 6 9...

result:

wrong answer 

Subtask #4:

score: 0
Wrong Answer

Test #83:

score: 60
Accepted
time: 0ms
memory: 3824kb

input:

341
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 2 1 0 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
1 3 0 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 2 1 0 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1...

result:

ok 

Test #84:

score: 60
Accepted
time: 4ms
memory: 3792kb

input:

103
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
1
1
1
1...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 7 8
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 4 7
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 5
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 8 0
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 2 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 5 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 6 9...

result:

ok 

Test #85:

score: 60
Accepted
time: 0ms
memory: 3864kb

input:

22
50 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
50 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
50 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 11 15
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 4 11
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 24 35
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 15 24
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 17 36
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 35 17
3kC2Ia2048BfyJVGojMUKKtilctlZKc...

result:

ok 

Test #86:

score: 60
Accepted
time: 0ms
memory: 4144kb

input:

8
128 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
128 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 11 69
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 110 11
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 119 35
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 69 119
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 17 109
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 35 17
3kC2Ia2048BfyJVGojMUKKtilc...

result:

ok 

Test #87:

score: 60
Accepted
time: 4ms
memory: 4164kb

input:

4
256 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 11 69
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 110 11
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 209 142
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 69 209
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 17 109
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 142 17
3kC2Ia2048BfyJVGojMUKKti...

result:

ok 

Test #88:

score: 60
Accepted
time: 0ms
memory: 3900kb

input:

341
3 1
1
1
0
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
1
1
3 1
1
1
0
1
1
3 1
1
1
0
1
1
3 1
1
1
0
1
1
3 1
0
1
1
1
1
3 1
1
1
0
1
1
3 1
1
1
0
1
1
3 1
1
1
1
1
3 1
0
1
1
1
1
3 1
0
1
1
1
1
3 1
0
1
1
1
1
3 1
1
1
1
1
3 1
0
1
1
1
1
3 1
1
1
0
1
1
3 1
0
1
1
1
1
3 1
0
1
1
1
1
3 1
1
1
1
1
3 1
1
1
0
1
1
3 1
0
1
1
1
1
...

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 2 1 0 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 1 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
1 3 2 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 2 1 0...

result:

ok 

Test #89:

score: 0
Wrong Answer
time: 1ms
memory: 3896kb

input:

103
10 1
1
1
1
1
1
1
1
1
1
1
1
10 1
0
1
1
1
1
1
1
1
1
1
1
1
10 1
0
1
1
1
1
1
1
1
1
1
1
1
10 1
1
1
1
1
1
1
1
0
1
1
1
1
10 1
1
1
1
1
0
1
1
1
1
1
1
1
10 1
1
0
1
1
1
1
1
1
1
1
1

output:

3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 7 8
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 4 7
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 0 5
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 8 0
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 2 1
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 5 2
3kC2Ia2048BfyJVGojMUKKtilctlZKcB
0 1 1 6 9...

result:

wrong answer