QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#111790#5665. AA Country and King Dreamoonxaphoenix#WA 0ms9564kbC++171.9kb2023-06-08 20:10:522023-06-08 20:10:55

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-08 20:10:55]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 9564kb
  • [2023-06-08 20:10:52]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define LC ch[k][0] 
#define RC ch[k][1]
#define IO cin.sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,n) for (int i = a; i < n; i++)
#define repn(i,a,n) for (int i = a; i <= n; i++)
#define per(i,a,n) for (int i = n - 1; i >= a; i--)
#define pern(i,a,n) for (int i = n; i >= a; i--)

typedef long long LL;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;

const int N = 600010;
const int M = 610000;
const int mod = 1e9+7;
const int inf = (int)1e9;
const LL INF = (LL)1e18;
const double eps = 1e-9;

int n, a[N], t[N], dep[N];
int fa[N];
vector<int> v1, v2; 

void solve() {
	cin >> n;
	int tot = 2 * n - 1;
	repn(i, 1, n) {
		dep[i] = 0; fa[i] = 0;
	}
	repn(i, 1, tot) cin >> a[i];
	a[1] = 1; a[tot] = 1;
	int l, r, pl;
	int d = 0;
	repn(i, 1, n) t[i] = 0;
	repn(i, 1, tot) {
		if (!a[i]) {
			l = a[i - 1]; pl = i;
			break;
		} 
		if (t[a[i]]) d --;
		else {
			fa[a[i]] = a[i - 1];
			d ++; t[a[i]] = 1;
		}
		dep[a[i]] = d;
	}
	d = 0;
	repn(i, 1, n) t[i] = 0;
	pern(i, 1, tot) {
		if (!a[i]) {
			r = a[i + 1];
			break;
		} 
		if (t[a[i]]) d --;
		else {
			fa[a[i]] = a[i + 1];
			d ++; t[a[i]] = 1;
		}
		dep[a[i]] = d;
	}
	v1.clear(); v2.clear();
	int val = r;
	if (l != r) {
		v2.pb(r);
		while (l != r) {
			if (dep[l] >= dep[r]) {
				l = fa[l]; if (l != r) v1.pb(l);
			}
			else {
				r = fa[r]; if (l != r) v2.pb(r);
			}
		}
		per(i, 0, v2.size()) v1.pb(v2[i]);
		for (auto x : v1) {
			a[pl ++] = x;
		}
	}
	repn(i, 1, n) {
		if (dep[i]) continue;
		a[pl ++] = i; a[pl ++] = val;
	}
	repn(i, 1, tot) cout << a[i] << " "; cout << "\n";
}

int main()
{
	IO;
	int T;
	cin >> T;
	repn(i, 1, T) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 9564kb

input:

9
5
1 2 3 2 0 2 1 5 1
5
1 2 3 0 0 2 1 5 1
5
1 2 0 0 0 2 1 5 1
5
1 2 0 0 0 0 1 5 1
5
1 0 0 0 0 0 1 5 1
5
1 0 0 0 0 0 0 5 1
5
1 0 0 0 0 0 0 0 1
5
1 0 0 0 0 0 0 0 0
5
0 0 0 0 0 0 0 0 0

output:

1 2 3 2 4 2 1 5 1 
1 2 3 2 4 2 1 5 1 
1 2 3 2 4 2 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 
1 5 2 5 3 5 4 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 

result:

wrong answer 6th lines differ - expected: '1 2 1 3 1 4 1 5 1', found: '1 5 2 5 3 5 4 5 1 '