QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#623651 | #6108. Permutation Arrangement | DreamAwaking | WA | 1ms | 3976kb | C++14 | 1.5kb | 2024-10-09 13:35:30 | 2024-10-09 13:35:31 |
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||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: 1ms
memory: 3824kb
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: 3932kb
input:
2 -1 -1
output:
-1
result:
ok 1 number(s): "-1"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3880kb
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: 0
Accepted
time: 1ms
memory: 3976kb
input:
10 -1 2 -1 6 -1 1 -1 5 -1 3
output:
4 2 8 6 9 1 7 5 10 3
result:
ok 10 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 3916kb
input:
10 -1 3 -1 -1 5 -1 9 -1 -1 -1
output:
1 3 6 2 5 7 9 4 8 10
result:
ok 10 numbers
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 3928kb
input:
10 4 -1 8 -1 -1 3 -1 9 -1 6
output:
-1
result:
wrong answer 1st numbers differ - expected: '4', found: '-1'