QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#186911 | #5665. AA Country and King Dreamoon | aesthetic | WA | 32ms | 7664kb | C++20 | 3.8kb | 2023-09-24 13:19:13 | 2023-09-24 13:19:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
// #define int ll
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
typedef pair<int, int> pii;
const int inf=INT_MAX;
const int maxn=1e6+10;
int n;
int mark[2][maxn];
int a[maxn];
int32_t main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ios::sync_with_stdio(0);cin.tie(0);
int T; cin>> T;
while(T--)
{
cin>> n;
for(int i=1; i<=n; i++)
mark[0][i]=mark[1][i]=0;
int sz=2*n-1;
for(int i=1; i<=sz; i++)
cin>> a[i];
vector<int> ida;
vector<int> volta;
int l, r;
for(int i=1; i<=sz; i++)
{
if(!a[i])
{
l=i;
break;
}
if(!mark[0][a[i]])
{
mark[0][a[i]]=1;
ida.pb(a[i]);
}
else
{
ida.pop_back();
}
}
for(int i=sz; i>=1; i--)
{
if(!a[i])
{
r=i;
break;
}
if(!mark[1][a[i]])
{
mark[1][a[i]]=1;
volta.pb(a[i]);
}
else
{
volta.pop_back();
}
}
vector<int> falta;
for(int i=1; i<=n; i++)
if(mark[0][i]==mark[1][i] && mark[1][i]==0)
falta.pb(i);
int szi=ida.size();
int szv=volta.size();
if(ida.empty() && volta.empty())
{
cout<< "1 ";
for(int i=2; i<=n; i++)
cout<< i<< " 1 ";
continue;
}
if(volta.empty())
{
for(int i=1; i<=l-1; i++)
cout<< a[i]<< " ";
for(int i=szi-2; i>=0; i--)
cout<< ida[i]<< " ";
for(int x: falta)
cout<< x<< " 1 ";
cout<< "\n";
continue;
}
if(ida.empty())
{
for(int x: falta)
cout<< "1 "<< x<< " ";
for(int i=0; i<=szv-2; i++)
cout<< volta[i]<< " ";
for(int i=r+1; i<=sz; i++)
cout<< a[i]<< " ";
cout<< "\n";
continue;
}
int cur=-1;
while(cur+1<min(szi, szv) && ida[cur+1]==volta[cur+1])
cur++;
// for(int x: ida)
// cout<< x<< " ";
// cout<< "\n";
// for(int x: volta)
// cout<< x<< " ";
// cout<< "\n";
// cout<< cur<< "\n";
vector<int> path;
int mn=n+1;
for(int i=szi-1; i>=cur; i--)
{
path.pb(ida[i]);
mn=min(mn, ida[i]);
}
for(int i=cur+1; i<szv; i++)
{
path.pb(volta[i]);
mn=min(mn, volta[i]);
}
// for(int x: path)
// cout<< x<< " ";
// cout<< "\n";
// cout<< mn<< "\n";
int szp=(int)path.size();
vector<int> ans;
for(int i=0; i<szp; i++)
{
ans.pb(path[i]);
if(path[i]==mn)
{
for(int x: falta)
{
ans.pb(x);
ans.pb(mn);
}
}
}
for(int i=1; i<=l-2; i++)
cout<< a[i]<< " ";
for(int x: ans)
cout<< x<< " ";
for(int i=r+2; i<=sz; i++)
cout<< a[i]<< " ";
cout<< "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5548kb
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: 32ms
memory: 7664kb
input:
28668 2 0 2 1 2 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