QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225473#5665. AA Country and King DreamoonBUET_TwilightWA 0ms12380kbC++233.2kb2023-10-24 18:03:482023-10-24 18:03:48

Judging History

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

  • [2023-10-24 18:03:48]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:12380kb
  • [2023-10-24 18:03:48]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
#define int long long
#define ll long long 
#define lll __int128_t
#define pb push_back
// #define double long double
#define pii pair<int,int>
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;
typedef pair<double, double> pdd;
const double EPS = 1e-12;


const int N = 300005;

vector<int> adj[N];
int pres[N];
void solve(){
    int n;
    cin>>n;
   
    for(int i=0;i<=n;i++) {
        adj[i].clear();
        pres[i] = 0;
    }
    pres[1] = 1;
    vector<int> prev,last;
    bool hasZero = false;
    
    for(int i=0;i<2*n-1;i++){
        int a;
        cin>>a;
        pres[a] = 1;
        if( a == 0 ){
            hasZero = true;
            continue;
        }
        if( !hasZero ) prev.push_back(a);
        else last.push_back(a);
    }
    if( last.size() == 0 ) last.push_back(1);
    if( prev.size() == 0 ) prev.push_back(1);

    for(int i=1;i<prev.size();i++){
        adj[prev[i-1]].push_back(prev[i]);
        adj[ prev[i] ].push_back(prev[i-1]);
    }
    for(int i=1;i<last.size();i++){
        adj[last[i-1]].push_back(last[i]);
        adj[ last[i] ].push_back(last[i-1]);
    }
    map<int,int> mp;
    for(int i=0;i<last.size();i++){
        mp[last[i]] = i;
    }
    int root = 1;
    int pos = last.size()-1;
    for(int i=prev.size()-1;i>=0;i--){
        if( mp.find(prev[i]) != mp.end() ){
            int cur = mp[prev[i]];
            if( cur<pos) {
                pos = cur;
                root = prev[i];
            }
        }
    }

    //cout<<root<<endl;

    vector<int> abs;
    for(int i=1;i<=n;i++) if( !pres[i] ) abs.push_back(i);

    vector<int> path;
    for(auto p:prev){
        if( path.size()>1 and path.back() == p ) {
            continue;
        }else if( path.size() > 1 and path[path.size()-2] == p ){
            path.pop_back();
            continue;
        }
        path.push_back(p);
    }

    //for(auto p:path) cout<<p<<" ";
    //cout<<endl;
    int cur = path.size()-1;
    for(auto a:abs){
        while( true  ){
            if( path.back() == root ) break;
            if( path[path.size()-2] > a ) break;
            path.pop_back();
            prev.push_back(path.back());
        }
       // cout<<path.back()<<"->"<<a<<endl;
        adj[path.back()].push_back(a);
        adj[a].push_back(path.back());
        path.push_back(a);
        prev.push_back(a);
    }
    for(auto p:prev) cout<<p<<" "; 
    for(auto l:last) cout<<l<<" ";
    cout<<endl;

}
signed main(){

    // ios_base::sync_with_stdio(false);
    // cin.tie(0);
    // cout.tie(0);
    int tc;
    cin>>tc;
    while(tc--)
    solve();
    
    return 0;
}

詳細信息

Test #1:

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

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 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:

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