QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#184439#5665. AA Country and King Dreamoonucup-team1508#WA 26ms5828kbC++141.6kb2023-09-20 19:16:452023-09-20 19:16:46

Judging History

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

  • [2023-09-20 19:16:46]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:5828kb
  • [2023-09-20 19:16:45]
  • 提交

answer

#include<bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i ++)
#define Fd(i, a, b) for(int i = a; i >= b; i --)
#define pii pair<int, int> 
#define fi first
#define se second
using namespace std;
const int N = 3e5 + 10;
int n, a[N], fa[N], vst[N];
void sol() {
    cin >> n;
    F(i, 1, 2 * n - 1) cin >> a[i];
    a[1] = a[2 * n - 1] = 1;
    F(i, 1, n) fa[i] = vst[i] = 0;
    vst[1] = 3;
    int pos = 0;
    F(i, 2, 2 * n - 1) {
        if(a[i] == 0) {
            pos = i; 
            break;
        }
        if(! vst[a[i]]) vst[a[i]] = 1, fa[a[i]] = a[i - 1];
        else if(fa[a[i - 1]] == a[i]) vst[a[i - 1]] = 3;
    }
    Fd(i, 2 * n - 2, 2) {
        if(a[i] == 0) break;
        if(! vst[a[i]]) vst[a[i]] = 2, fa[a[i]] = a[i + 1];
        else if(fa[a[i]] == a[i + 1]) vst[a[i]] = 3;
    }
    // F(i, 1, n) cout << fa[i] << " \n" [i == n];
    priority_queue<int, vector<int>, greater<int> > q;
    F(i, 1, n) if(! vst[i] || vst[i] == 2) q.push(i);
    F(i, pos, 2 * n - 1) {
        if(a[i]) break;
        int x = 0, y = fa[a[i - 1]];
        if(q.size()) x = q.top();
        if(x && (vst[a[i - 1]] == 2 || vst[a[i - 1]] == 3 || x < y)) {
            a[i] = q.top();
            fa[a[i]] = a[i - 1];
            if(vst[a[i]] == 2) vst[a[i]] = 3;
            else vst[a[i]] = 1;
            q.pop();
            continue;
        }
        vst[a[i - 1]] = 3;
        a[i] = fa[a[i - 1]];
    }
    F(i, 1, 2 * n - 1) cout << a[i] << " \n" [i == 2 * n - 1];
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t; cin >> t;
    while(t --) sol();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5828kb

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 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
1 2 1 3 1 4 1 5 1

result:

ok 9 lines

Test #2:

score: -100
Wrong Answer
time: 26ms
memory: 5648kb

input:

28668
2
0 2 1
2
0 0 1
2
0 0 0
2
1 0 1
2
1 0 0
2
1 2 0
3
0 2 1 3 1
3
0 0 1 3 1
3
0 0 0 3 1
3
0 0 0 0 1
3
0 0 0 0 0
3
1 0 1 3 1
3
1 0 0 3 1
3
1 0 0 0 1
3
1 0 0 0 0
3
1 2 0 3 1
3
1 2 0 0 1
3
1 2 0 0 0
3
1 2 1 0 1
3
1 2 1 0 0
3
1 2 1 3 0
3
0 2 3 2 1
3
0 0 3 2 1
3
0 0 0 2 1
3
1 0 3 2 1
3
1 0 0 2 1
3
1 2 ...

output:

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

result:

wrong answer 32nd lines differ - expected: '1 3 1 2 1', found: '1 2 1 2 1'