QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#199653#7346. FrogsVengeful_Spirit#WA 1ms3612kbC++14863b2023-10-04 13:33:082023-10-04 13:33:08

Judging History

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

  • [2023-10-04 13:33:08]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3612kb
  • [2023-10-04 13:33:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[N], p[N];

void fail() {
    cout << "No\n";
    exit(0);
}

void solve(int l, int r, int now) {
    if(l > r) return ;
    int flg = 1, last = l;
    for(int i = l; i <= r; ++i) {
        if(a[i] == now) {
            flg = 0;
            solve(last, i - 1, now);
            last = i + 1;
        }
    }
    if(flg) {
        if(a[l] != now + 2 || a[r] != now + 2) fail();
        swap(p[l], p[r + 1]);
        solve(l + 1, r - 1, now + 2);
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i < n; ++i) cin >> a[i];
    for(int i = 1; i <= n; ++i) p[i] = i;
    solve(1, n - 1, 0);
    cout << "Yes\n";
    for(int i = 1; i <= n; ++i) cout << p[i] << " "; cout << "\n";
    return 0;
}

详细

Test #1:

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

input:

5
2 4 2 2

output:

Yes
5 3 2 4 1 

result:

ok Correct answer.

Test #2:

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

input:

4
1 2 3

output:

No

result:

ok Correct answer.

Test #3:

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

input:

2
0

output:

Yes
1 2 

result:

ok Correct answer.

Test #4:

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

input:

2
2

output:

Yes
2 1 

result:

ok Correct answer.

Test #5:

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

input:

2
1

output:

No

result:

ok Correct answer.

Test #6:

score: 0
Accepted
time: 1ms
memory: 3396kb

input:

3
0 0

output:

Yes
1 2 3 

result:

ok Correct answer.

Test #7:

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

input:

3
2 0

output:

Yes
2 1 3 

result:

ok Correct answer.

Test #8:

score: -100
Wrong Answer
time: 0ms
memory: 3448kb

input:

3
0 2

output:

Yes
1 2 3 

result:

wrong answer Output permutation must generate the input sequence.