QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#199672#7346. FrogsVengeful_Spirit#RE 1ms7804kbC++141.1kb2023-10-04 13:38:562023-10-04 13:38:56

Judging History

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

  • [2023-10-04 13:38:56]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:7804kb
  • [2023-10-04 13:38:56]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[N], p[N], qz[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);
    for(int i = 1; i <= n; ++i) {
        int l = i, r = p[i];
        if(l > r) swap(l, r);
        qz[l]++, qz[r]--;
    }
    for(int i = 1; i < n; ++i) {
        qz[i] += qz[i - 1];
        assert(qz[i] == a[i]);
    }
    cout << "Yes\n";
    for(int i = 1; i <= n; ++i) cout << p[i] << " "; cout << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

4
1 2 3

output:

No

result:

ok Correct answer.

Test #3:

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

input:

2
0

output:

Yes
1 2 

result:

ok Correct answer.

Test #4:

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

input:

2
2

output:

Yes
2 1 

result:

ok Correct answer.

Test #5:

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

input:

2
1

output:

No

result:

ok Correct answer.

Test #6:

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

input:

3
0 0

output:

Yes
1 2 3 

result:

ok Correct answer.

Test #7:

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

input:

3
2 0

output:

Yes
2 1 3 

result:

ok Correct answer.

Test #8:

score: -100
Runtime Error

input:

3
0 2

output:


result: