QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#722809 | #1873. Array | Made_in_Code | WA | 0ms | 5632kb | C++14 | 1.2kb | 2024-11-07 20:14:33 | 2024-11-07 20:14:36 |
Judging History
answer
#include <iostream>
using namespace std;
const int kMaxN = 5e5 + 1;
int t, n, m, k, a[kMaxN], b[kMaxN];
void Solve() {
cin >> n, m = n, k = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i], b[i] = 0;
}
for (int i = 1; i <= n; i++) {
if (a[i] <= n) {
m = min(m, a[i] - i + 1);
}
if (a[i] < i || a[i] < a[i - 1]) {
cout << "NO\n";
return;
}
}
if (a[1] == n + 1) {
cout << "NO\n";
return;
}
for (int i = 1; i < m; i++) {
b[i] = i;
}
b[a[1]] = m;
for (int i = 1; i < n; i++) {
for (; k <= n && b[k]; k++) {
}
if (!b[i]) {
cout << "NO\n";
return;
} else if (a[i] == a[i + 1]) {
b[k] = b[i];
} else if (a[i + 1] <= n) {
b[a[i + 1]] = b[i];
} else if (i + 1 == k) {
cout << "NO\n";
return;
} else {
break;
}
}
for (; k <= n; k++) {
!b[k] && (b[k] = b[k - 1]);
}
cout << "YES\n";
for (int i = 1; i <= n; i++) {
cout << b[i] << " \n"[i == n];
}
}
int main() {
cin.tie(0), cout.tie(0);
ios::sync_with_stdio(0);
cin >> t;
while (t--) {
Solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5632kb
input:
3 4 3 3 5 5 7 4 6 6 7 8 8 8 5 2 3 4 4 6
output:
YES 1 1 2 2 YES 1 2 3 4 2 1 3 NO
result:
wrong output format Expected integer, but "YES" found