QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#623651#6108. Permutation ArrangementDreamAwakingWA 1ms3976kbC++141.5kb2024-10-09 13:35:302024-10-09 13:35:31

Judging History

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

  • [2024-10-09 13:35:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3976kb
  • [2024-10-09 13:35:30]
  • 提交

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'