QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#623637 | #6108. Permutation Arrangement | DreamAwaking | WA | 1ms | 3916kb | C++14 | 1.5kb | 2024-10-09 13:32:01 | 2024-10-09 13:32:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
int flag[maxn];
void solve(){
int n;
cin>>n;
vector<int> v;
v.push_back(-1);
for(int i=1;i<=n;i++){
int num;
cin>>num;
flag[num]=1;
v.push_back(num);
}
priority_queue<int,vector<int>,greater<int>> pri;
vector<int> ans(maxn,-1);
for(int i=1;i<=n;i++){
if(!flag[i]) pri.push(i);
}
for(int i=1;i<=n;i++){
if(v[i]) ans[i]=v[i];
}
int cnt=1;
for(int i=1;i<=n;i++){
if(ans[i]==-1){
if(pri.empty()){
cnt=0;
break;
}
vector<int> tmp;
while(1){
if(pri.empty()){
cnt=0;
break;
}
int num=pri.top();
pri.pop();
if(abs(ans[i-1]-num)<=1){
tmp.push_back(num);
}
else{
ans[i]=num;
break;
}
}
if(!cnt) break;
for(auto x:tmp){
pri.push(x);
}
}
}
if(!cnt) cout<<"-1"<<'\n';
else{
for(int i=1;i<=n;i++){
cout<<ans[i]<<" ";
}
}
}
int main(){
std::ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t;
t=1;
while(t--){
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
input:
10 3 -1 10 -1 8 -1 -1 -1 -1 -1
output:
3 1 10 2 8 4 6 9 5 7
result:
ok 10 numbers
Test #2:
score: 0
Accepted
time: 1ms
memory: 3880kb
input:
2 -1 -1
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3916kb
input:
10 -1 -1 -1 8 -1 2 10 -1 -1 3
output:
1 4 6 8 5 2 10 7 9 3
result:
ok 10 numbers
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3864kb
input:
10 -1 2 -1 6 -1 1 -1 5 -1 3
output:
4 2 7 6 8 1 9 5 10 3
result:
wrong answer 3rd numbers differ - expected: '8', found: '7'