QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#420835 | #1873. Array | XZC0920 | WA | 185ms | 8332kb | C++14 | 1.8kb | 2024-05-24 22:50:43 | 2024-05-24 22:50:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int t, n, a[N], u, fa[N], r[N], c[N], cn, ct, ans[N], v, b[N], bn;
void solve()
{
scanf("%d", &n); u = fa[0] = bn = cn = 0; ct = 0;
for(int i = 1; i <= n; i++)
{
scanf("%d", &a[i]); fa[i] = 0, r[i] = -1;
if(a[i] != n + 1) u = i;
}
if(u == 0) return printf("-1\n"), void();
bool ok = 1;
for(int i = 1; i <= n; i++) ok &= (a[i] == i);
if(ok)
{
for(int i = 1; i <= n; i++) printf("1 ");
printf("\n"); return;
}
for(int i = 0; i < u; i++)
{
if(a[i] != a[i + 1])
{
fa[i] = a[i + 1];
for(int j = a[i] + 1; j < a[i + 1]; j++) r[j] = i;
}
}
for(int i = 1; i < a[u]; i++) if(!fa[i] && i != u) c[++cn] = i;
for(int i = a[u]; i >= 1; i--)
{
if(r[i] == -1 || r[i] == 0) continue;
while(cn && c[cn] >= i) cn--;
if(cn == 0) return printf("-1\n"), void();
int j = c[cn--];
if(j <= r[i]) return printf("-1\n"), void();
fa[j] = i;
}
for(int i = u; i <= n; i++) if(r[i] == 0) b[++bn] = i;
for(int i = 1; i < u; i++)
{
if(!fa[i])
{
if(bn == 0) return printf("-1\n"), void();
fa[i] = b[bn--];
}
}
for(int i = a[u]; i >= 1; i--)
{
if(!fa[i]) ans[i] = ++ct;
else ans[i] = ans[fa[i]];
}
for(int i = a[u] + 1; i <= n; i++)
{
if(ans[u] == 1 && ct == 1) return printf("-1\n"), void();
ans[i] = (ans[u] == 1 ? 2 : 1);
}
for(int i = 1; i <= n; i++) printf("%d ", ans[i]);
printf("\n");
}
int main()
{
scanf("%d", &t);
while(t--) solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5968kb
input:
3 4 3 3 5 5 7 4 6 6 7 8 8 8 5 2 3 4 4 6
output:
2 2 1 1 2 3 1 4 3 2 1 -1
result:
ok 233
Test #2:
score: -100
Wrong Answer
time: 185ms
memory: 8332kb
input:
23198 7 1 2 3 4 5 6 7 7 1 2 3 4 5 6 8 7 1 2 3 4 5 7 7 7 1 2 3 4 5 7 8 7 1 2 3 4 5 8 8 7 1 2 3 4 6 6 7 7 1 2 3 4 6 6 8 7 1 2 3 4 6 7 7 7 1 2 3 4 6 7 8 7 1 2 3 4 6 8 8 7 1 2 3 4 7 7 7 7 1 2 3 4 7 7 8 7 1 2 3 4 7 8 8 7 1 2 3 4 8 8 8 7 1 2 3 5 5 6 7 7 1 2 3 5 5 6 8 7 1 2 3 5 5 7 7 7 1 2 3 5 5 7 8 7 1 2 ...
output:
1 1 1 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...
result:
wrong answer oh no! -1