QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#134121 | #5665. AA Country and King Dreamoon | Nicolas125841 | RE | 0ms | 3456kb | C++17 | 4.1kb | 2023-08-03 07:21:38 | 2023-08-03 07:21:40 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(NULL)->sync_with_stdio(false);
int t;
cin >> t;
while(t--){
int n;
cin >> n;
vector<int> path(2 * n - 1);
for(int i = 0; i < path.size(); i++)
cin >> path[i];
path[0] = path[path.size() - 1] = 1;
vector<int> fjmp(n + 1, -1);
vector<int> bjmp(n + 1, -1);
vector<int> pstack;
set<int> fnodes;
int ind = 0;
for(int i = 1; i <= n; i++)
fnodes.insert(i);
for(int i = 0; i < path.size(); i++){
if(path[i] == 0)
break;
ind = i + 1;
fjmp[path[i]] = i;
if(pstack.size() > 1 && path[i] == pstack[pstack.size() - 2])
pstack.pop_back();
else
pstack.push_back(path[i]);
fnodes.erase(path[i]);
}
for(int i = path.size()-1; i >= 0; i--){
if(path[i] == 0)
break;
fnodes.erase(path[i]);
bjmp[path[i]] = i;
}
int snode = 1;
int bp = bjmp[1];
while(fjmp[path[bp - 1]] != -1){
snode = path[bp - 1];
bp = bjmp[path[bp - 1]];
}
while(path[ind] == 0){
if(!fnodes.empty()){
if(pstack.back() == snode){
if(path[bp - 1] == 0 || *fnodes.begin() < path[bp - 1]){
pstack.push_back(*fnodes.begin());
path[ind] = *fnodes.begin();
fnodes.erase(fnodes.begin());
}else{
path[ind] = path[bp - 1];
snode = path[bp - 1];
pstack.push_back(path[bp - 1]);
bp = bjmp[path[bp - 1]];
}
}else if(path[bp - 1] == 0){
if(*fnodes.begin() < pstack[pstack.size() - 2]){
pstack.push_back(*fnodes.begin());
path[ind] = *fnodes.begin();
fnodes.erase(fnodes.begin());
}else{
pstack.pop_back();
path[ind] = pstack.back();
}
}else{
if(*fnodes.begin() < path[bp - 1] && *fnodes.begin() < pstack[pstack.size() - 2]){
pstack.push_back(*fnodes.begin());
path[ind] = *fnodes.begin();
fnodes.erase(fnodes.begin());
}else if(path[bp - 1] < pstack[pstack.size() - 2] && path[bp - 1] < *fnodes.begin()){
path[ind] = path[bp - 1];
snode = path[bp - 1];
pstack.push_back(path[bp - 1]);
bp = bjmp[path[bp - 1]];
}else{
pstack.pop_back();
path[ind] = pstack.back();
}
}
}else{
assert(!(pstack.back() == snode && path[bp - 1] == 0));
if(pstack.back() == snode){
path[ind] = path[bp - 1];
snode = path[bp - 1];
pstack.push_back(path[bp - 1]);
bp = bjmp[path[bp - 1]];
}else if(path[bp - 1] == 0 || pstack[pstack.size() - 2] < path[bp - 1]){
pstack.pop_back();
path[ind] = pstack.back();
}else{
path[ind] = path[bp - 1];
snode = path[bp - 1];
pstack.push_back(path[bp - 1]);
bp = bjmp[path[bp - 1]];
}
}
ind++;
}
for(int &v : path)
cout << v << " ";
cout << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3456kb
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
Dangerous Syscalls
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 ...