QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#736813#5665. AA Country and King DreamoonSanguineChameleon#WA 30ms3772kbC++203.1kb2024-11-12 13:31:062024-11-12 13:31:11

Judging History

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

  • [2024-11-12 13:31:11]
  • 评测
  • 测评结果:WA
  • 用时:30ms
  • 内存:3772kb
  • [2024-11-12 13:31:06]
  • 提交

answer

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

void justDoIt();

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    justDoIt();
    return 0;
}

void test() {
    int n;
    cin >> n;
    vector<bool> flag(n + 1, false);
    vector<int> a(n * 2 - 1);
    for (int i = 0; i < (int)a.size(); i++) {
        cin >> a[i];
    }
    a[0] = 1;
    a.back() = 1;
    int p = -1;
    for (int i = 0; i < (int)a.size(); i++) {
        if (a[i] == 0) {
            p = i;
            break;
        }
    }
    if (p == -1) {
        for (auto u: a) {
            cout << u << " ";
        }
        cout << '\n';
        return;
    }
    for (auto u: a) {
        flag[u] = true;
    }
    vector<int> prefPath = {1};
    for (int i = 1; i < (int)a.size() && a[i] != 0; i++) {
        int u = a[i];
        if ((int)prefPath.size() >= 2 && prefPath.end()[-2] == u) {
            prefPath.pop_back();
        }
        else {
            prefPath.push_back(u);
        }
    }
    vector<int> sufPath = {1};
    for (int i = (int)a.size() - 2; i >= 0 && a[i] != 0; i--) {
        int u = a[i];
        if ((int)sufPath.size() >= 2 && sufPath.end()[-2] == u) {
            sufPath.pop_back();
        }
        else {
            sufPath.push_back(u);
        }
    }
/*    for (auto u: prefPath) {
        cout << u << " ";
    }
    cout << endl;
    for (auto u: sufPath) {
        cout << u << " ";
    }
    cout << endl;*/
    int match = 0;
    for (; match < (int)prefPath.size() && match < (int)sufPath.size() && prefPath[match] == sufPath[match]; match++) {
        ;
    }
    vector<int> orig;
    for (int i = match - 1; i < (int)prefPath.size() - 1; i++) {
        orig.push_back(prefPath[i]);
    }
    reverse(orig.begin(), orig.end());
    for (int i = match; i < (int)sufPath.size(); i++) {
        orig.push_back(sufPath[i]);
    }
    vector<int> rem;
    for (int u = n; u >= 1; u--) {
        if (!flag[u]) {
            rem.push_back(u);
        }
    }
    int prv = a[p - 1];
    for (auto u: orig) {
        //cout << "orig " << u << endl;
        vector<int> small;
        while (!rem.empty() && rem.back() < u) {
            small.push_back(rem.back());
            rem.pop_back();
        }
        if (!small.empty()) {
            if (small[0] < prv) {
                a[p++] = small[0];
                for (int i = 1; i < (int)small.size(); i++) {
                    a[p++] = small[i];
                    a[p++] = small[0];
                }
                a[p++] = prv;
            }
            else {
                for (auto u: small) {
                    a[p++] = u;
                    a[p++] = prv;
                }
            }
        }
        a[p++] = u;
        prv = u;
    }
    reverse(rem.begin(), rem.end());
    for (auto u: rem) {
        a[p++] = u;
        a[p++] = prv;
    }
    for (auto u: a) {
        cout << u << " ";
    }
    cout << '\n';
}

void justDoIt() {
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        test();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3772kb

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: 30ms
memory: 3512kb

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...

result:

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