QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#737278#5665. AA Country and King DreamoonSanguineChameleon#WA 30ms3620kbC++203.0kb2024-11-12 15:17:412024-11-12 15:17:43

Judging History

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

  • [2024-11-12 15:17:43]
  • 评测
  • 测评结果:WA
  • 用时:30ms
  • 内存:3620kb
  • [2024-11-12 15:17:41]
  • 提交

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);
        }
    }
/*    vector<int> small;
    while (!rem.empty() && rem.back() < prefPath.back()) {
        small.push_back(rem.back());
        rem.pop_back();
    }
    for (auto u: small) {
        a[p++] = u;
        a[p++] = prv;
    }*/
    int cur = a[p - 1];
    reverse(orig.begin(), orig.end());
    while (!orig.empty()) {
        int u = orig.back();
        if (!rem.empty() && rem.back() < u) {
            orig.push_back(cur);
            a[p++] = rem.back();
            cur = rem.back();
            rem.pop_back();
        }
        else {
            a[p++] = u;
            orig.pop_back();
            cur = u;
        }
    }
    reverse(rem.begin(), rem.end());
    for (auto u: rem) {
        a[p++] = u;
        a[p++] = cur;
    }
    for (auto u: a) {
        cout << u << " ";
    }
    cout << '\n';
}

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

詳細信息

Test #1:

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

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: 3620kb

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 '