QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#104089#5665. AA Country and King DreamoontarjenWA 133ms3368kbC++171.9kb2023-05-08 16:16:572023-05-08 16:17:02

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-08 16:17:02]
  • 评测
  • 测评结果:WA
  • 用时:133ms
  • 内存:3368kb
  • [2023-05-08 16:16:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const bool test=false;
void solve()
{
    int n;cin>>n;
    vector<int> a(n*2);
    for(int i=1;i<2*n;i++)cin>>a[i];
    a[1]=a[2*n-1]=1;
    set<int>s;
    for(int i=1;i<=n;i++)s.insert(i);
    for(int i=1;i<2*n;i++)if(s.find(a[i])!=s.end())s.erase(a[i]);
    vector<int> sta1,sta2;
    for(int i=1;i<2*n;i++){
        if(a[i]==0)break;
        if(sta1.size()>=2&&sta1[(int)sta1.size()-2]==a[i])sta1.pop_back();
        else sta1.push_back(a[i]);
    }
    for(int i=2*n-1;i>=1;i--){
        if(a[i]==0)break;
        if(sta2.size()>=2&&sta2[(int)sta2.size()-2]==a[i])sta2.pop_back();
        else sta2.push_back(a[i]);
    }
    int now=0;
    for(int i=1;i<2*n;i++)if(a[i]==0){
        now=i;break;
    }
    vector<int> sta;
    int node=sta1.back();
    int g=0;
    for(g=0;g<(int)min(sta1.size(),sta2.size());g++){
        if(sta1[g]!=sta2[g])break;
    }
    // cout<<"g="<<g<<"\n";
    for(int i=(int)sta1.size()-1;i>=g;i--)sta.push_back(sta1[i]); 
    for(int i=g-1;i<(int)sta2.size();i++)sta.push_back(sta2[i]); 
    if(test){
        cout<<"sta1 :";for(auto it:sta1)cout<<it<<" ";;cout<<"\n";
        cout<<"sta2 :";for(auto it:sta2)cout<<it<<" ";;cout<<"\n";
        cout<<"sta :";for(auto it:sta)cout<<it<<" ";;cout<<"\n";
    }
    reverse(sta.begin(),sta.end());
    if((int)sta.size()>0&&sta.back()==node)sta.pop_back();
    while(a[now]==0){
        int g=1e9;if(sta.size()>0)g=sta.back();
        int t=1e9;if(s.size()>0)t=*s.begin();
        if(g<t){
            a[now++]=g;sta.pop_back();
            node=g;
        }
        else{
            sta.push_back(node);
            s.erase(t);
            a[now++]=t;
        }
    }
    for(int i=1;i<2*n;i++)cout<<a[i]<<" ";;cout<<"\n";
}
int main()
{
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    int T;cin>>T;while(T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3368kb

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:

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

result:

ok 9 lines

Test #2:

score: -100
Wrong Answer
time: 133ms
memory: 3340kb

input:

28668
2
0 2 1
2
0 0 1
2
0 0 0
2
1 0 1
2
1 0 0
2
1 2 0
3
0 2 1 3 1
3
0 0 1 3 1
3
0 0 0 3 1
3
0 0 0 0 1
3
0 0 0 0 0
3
1 0 1 3 1
3
1 0 0 3 1
3
1 0 0 0 1
3
1 0 0 0 0
3
1 2 0 3 1
3
1 2 0 0 1
3
1 2 0 0 0
3
1 2 1 0 1
3
1 2 1 0 0
3
1 2 1 3 0
3
0 2 3 2 1
3
0 0 3 2 1
3
0 0 0 2 1
3
1 0 3 2 1
3
1 0 0 2 1
3
1 2 ...

output:

1 2 1 
1 2 1 
1 2 1 
1 2 1 
1 2 1 
1 2 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3...

result:

wrong answer 428th lines differ - expected: '1 4 2 3 2 4 1', found: '1 4 2 3 4 4 1 '