QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#199653 | #7346. Frogs | Vengeful_Spirit# | WA | 1ms | 3612kb | C++14 | 863b | 2023-10-04 13:33:08 | 2023-10-04 13:33:08 |
Judging History
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.