QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#732738 | #5665. AA Country and King Dreamoon | Ashbourne | WA | 49ms | 7704kb | C++20 | 1.6kb | 2024-11-10 15:43:53 | 2024-11-10 15:43:59 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 10;
int a[N], Ton[N], fa[N];
void solve(){
int n, l = 0, r = n;
cin >> n;
vector<int> vis(n + 100);
for(int i = 1; i <= n; ++ i) Ton[i] = 0, fa[i] = 0;
// vector<int> a(2 * n + 1);
a[0] = 1e14; a[2 * n] = 1e14;
for(int i = 1; i <= 2 * n - 1; ++ i) cin >> a[i];
for(int i = 1; i <= 2 * n - 1; ++ i){
vis[a[i]] = 1;
if(a[i - 1] && !a[i]) l = i;
if(!a[i] && a[i + 1]) r = i;
}
int lx, rx;
vis[n + 1] = 1;
for(int i = 1; i <= n; ++ i){
if(vis[i - 1] && !vis[i]) lx = i;
if(!vis[i] && vis[i + 1]) rx = i;
}
// cout << l << " " << r << endl;
for(int i = r + 1; i <= 2 * n - 1; ++ i) Ton[a[i]]++;
if(l == 1 && r == 2 * n - 1){
for(int i = 1; i <= 2 * n - 1; ++ i){
if(i % 2 == 1) a[i] = 1;
else a[i] = i / 2 + 1;
cout << a[i] << " ";
}
cout << endl;
return;
}
if(l == 1){
a[1] = a[2 * n - 1];
l++;
}
// cout << l << " " << r << endl;
fa[a[1]] = 1e14;
for(int i = 2; i <= l - 1; ++ i){
if(!fa[a[i]]) fa[a[i]] = a[i - 1];
}
// cout << fa[3] << endl;
for(int i = l; i <= r; ++ i){
int rd = fa[a[i - 1]];
// cout << rd << endl;
bool flag = 1;
if(rd == 1e14 || Ton[a[i - 1]]) flag = 0;
// cout << flag << endl;
if(flag && (rd < lx || lx > rx)){
a[i] = rd;
}else{
a[i] = lx++;
fa[a[i]] = a[i - 1];
}
}
for(int i = 1; i <= 2 * n - 1; ++i ){
cout << a[i] << " ";
}
cout << endl;
}
signed main(){
ios::sync_with_stdio(0);
int T;
cin >> T;
while(T--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7684kb
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: 49ms
memory: 7704kb
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 0 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 0 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 0 1 2 3 2 1 1 0 3 2 1 1 3 1 2 1 1 0 3 2 1 1 3 1 2 1 1 2 3 2 1 1 2 3 0 1 1 2 3 0 3 1 2 3...
result:
wrong answer 6th lines differ - expected: '1 2 1', found: '1 2 0 '