QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#549051 | #5665. AA Country and King Dreamoon | skrghariapa | RE | 0ms | 3652kb | C++17 | 2.4kb | 2024-09-06 01:21:25 | 2024-09-06 01:21:26 |
Judging History
answer
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
using ll = long long;
vector<int> ke;
vector<bool> vis;
vector<bool> gabolehmundur;
vector<int> par;
void solve(){
int n, noldepan = -1, nolbelakang, dump;
cin>>n;
queue<int> q;
int cq = 0;
nolbelakang = 2*n-2;
ke.clear();
ke.resize(2*n+5, 0);
vis.clear();
vis.resize(n+3, false);
gabolehmundur.clear();
gabolehmundur.resize(n+3, false);
par.clear();
par.resize(n+3, 500000);
cin>>dump;
ke[0] = 1;
ke[2*n-2] = 1;
vis[1] = true;
// isi sama nandain nol
for(int i = 1; i < 2*n-2; i++){
cin>>ke[i];
if(ke[i] == 0 && ke[i-1] != 0){
noldepan = i;
}
if(ke[i] != 0 && ke[i-1] == 0){
nolbelakang = i-1;
}
vis[ke[i]] = true;
}
cin>>dump;
// liat yang kosong
for(int i = 1; i <= n; i++){
if(!vis[i]){
q.push(i);
cq++;
}
}
// ngasi parent
for(int i = 1; i < noldepan; i++){
if(par[ke[i-1]] != ke[i]){
par[ke[i]] = ke[i-1];
}
}
for(int i = 2*n - 3; i > nolbelakang; i--){
if(par[ke[i+1]] != ke[i]){
par[ke[i]] = ke[i+1];
}
}
// ngasi gaboleh mundur
for(int i = nolbelakang+1; i < 2*n-1; i++){
if(i != 0 && ke[i] == par[ke[i-1]]) gabolehmundur[ke[i-1]] = true;
}
gabolehmundur[1] = true;
// for(int i = 1; i <= n; i++){
// if(gabolehmundur[i]) cout<<i<<endl;
// }
// ngisi nol
for(int i = noldepan; i <= nolbelakang; i++){
if(gabolehmundur[ke[i-1]]){
ke[i] = q.front();
// cout<<q.front()<<endl;
par[ke[i]] = ke[i -1];
q.pop();
cq--;
}
else{
if(cq==0 || par[ke[i - 1]] < q.front()){
ke[i] = par[ke[i - 1]];
gabolehmundur[ke[i - 1]] = true;
}
else{
ke[i] = q.front();
q.pop();
cq--;
}
}
}
for(int i = 0; i < 2*n-2; i++){
cout<<ke[i]<<" ";
}
cout<<ke[2*n-2]<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
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
Runtime Error
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 ...