QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#220129#5665. AA Country and King DreamoonZIhan#WA 0ms3608kbC++203.2kb2023-10-19 22:32:012023-10-19 22:32:02

Judging History

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

  • [2023-10-19 22:32:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3608kb
  • [2023-10-19 22:32:01]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IO ios::sync_with_stdio(0),cin.tie(0); 
using namespace std;
void solve(){
    int n;
    cin>>n;
    cout<<n<<"\n";
    if(n==1){
        cout<<1<<"\n";
        return;
    }
    int N=2*n-1;
    vector<int> now(N,-1);
    vector<int> sta={1};
    vector<int> visit(n+2);
    vector<int> nowk;
    vector<int> nowk_val;
    vector<int> vis(n+1);
    vector<int> vec;
    vector<int> zero;
    int l=0,r=0;
    for(int i=0;i<N;i++){
        int x;
        cin>>x;
        vis[x]=1;
        vec.push_back(x);
    }
    for(int i=n;i>=1;i--){
        if(vis[i]==0) zero.push_back(i);
    }
    for(int i=0;i<=N-1;i++){
        if(vec[i]==0){
            l=i;
            break;
        }
    }
    for(int i=N-1;i>=0;i--){
        r=i;
        break;
    }
    if(!l) vec[0]=1,l++;
    if(r!=N-1) vec[r]=1,r--;
    if(l>r){
        for(int i=0;i<N;i++){
            cout<<vec[i]<<" \n"[i==N-1];
        }
        return;
    }
    if(!zero.empty()&&zero.back()==1) zero.pop_back();
    for(int i=r+1;i<=N-1;i++){
        if(now[vec[i]]==-1) now[vec[i]]=i;
    }
    for(int i=1;i<=l-1;i++){
        if(visit[vec[i]]) sta.pop_back();
        else sta.push_back(vec[i]),visit[i]=1;
    }
    reverse(sta.begin(),sta.end());
    for(int i=0;i<sta.size();i++){
        if(now[i]!=-1){
            nowk.push_back(now[i]);
            break;
        }
    }
    reverse(sta.begin(),sta.end());
    while(1){
        if(nowk.empty()) break;
        if(nowk.back()-1>r) nowk.push_back(now[vec[nowk.back()-1]]);
        else break;
    }
    for(int i=0;i<now.size();i++) nowk_val.push_back(vec[i]);
    reverse(nowk.begin(),nowk.end());
    reverse(nowk_val.begin(),nowk_val.end());
    for(int i=l;i<=r;i++){
        if(sta.back()==nowk_val.back()){
            if(!zero.empty()){
                if(nowk.size()<=1||zero.back()<nowk_val[nowk_val.size()-2]){
                    vec[i]=zero.back();
                    sta.push_back(zero.back());
                    zero.pop_back();
                }
                else{
                    vec[i]=nowk_val[nowk_val.size()-2];
                    sta.push_back(nowk_val[nowk_val.size()-2]);
                    nowk_val.pop_back();
                }
            }
            else{
                vec[i]=nowk_val[nowk_val.size()-2];
                sta.push_back(nowk_val[nowk_val.size()-2]);
                nowk_val.pop_back();
            }
        }
        else{
            if(!zero.empty()){
                if(zero.back()<sta[sta.size()-2]){
                    vec[i]=zero.back();
                    sta.push_back(zero.back());
                    zero.pop_back();
                }
                else{
                    vec[i]=sta[sta.size()-2];
                    sta.pop_back();
                }
            }
            else{
                vec[i]=sta[sta.size()-2];
                sta.pop_back();
            }
        }
    }
    for(int i=0;i<N;i++){
        cout<<vec[i]<<" \n"[i==N-1];
    }
}
signed main(){
    IO
    int t;
    cin>>t;
    while(t--){
        solve();
    }

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3608kb

input:

9
5
1 2 3 2 0 2 1 5 1
5
1 2 3 0 0 2 1 5 1
5
1 2 0 0 0 2 1 5 1
5
1 2 0 0 0 0 1 5 1
5
1 0 0 0 0 0 1 5 1
5
1 0 0 0 0 0 0 5 1
5
1 0 0 0 0 0 0 0 1
5
1 0 0 0 0 0 0 0 0
5
0 0 0 0 0 0 0 0 0

output:

5
1 2 3 2 1 4 1 2 3
5
1 2 3 2 1 4 1 2 3
5
1 2 1 3 1 4 1 2 0
5
1 2 1 3 1 4 1 2 0
5
1 2 1 3 1 4 1 0 0
5
1 2 1 3 1 4 1 0 0
5
1 2 1 3 1 4 1 5 1
5
1 2 1 3 1 4 1 5 1
5
1 2 1 3 1 4 1 5 1

result:

wrong answer 1st lines differ - expected: '1 2 3 2 4 2 1 5 1', found: '5'