QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#627816 | #7757. Palm Island | Lanzy | TL | 1ms | 5896kb | C++23 | 2.4kb | 2024-10-10 17:15:52 | 2024-10-10 17:15:53 |
Judging History
answer
#include <bits/stdc++.h>
// #include <bits/extc++.h>
#pragma GCC optimize (1)
#pragma GCC optimize (2)
#pragma GCC optimize (3)
#define int long long
#define IOS ios::sync_with_stdio(0),cin.tie(0)
// using namespace __gnu_pbds;
using namespace std;
const int N=2e5+10,M=1e6+10,mod=1e9+7;
vector<int>ans;
deque<array<int,5>>d;
deque<int>c;
int L[N],R[N];
inline void f2(){
if(d.size()<=1) return;
auto x=d[0];
d.pop_front();
int s=d[0][2];
while(s--){
ans.push_back(2);
}
d.push_back(d[0]);
d.pop_front();
d.push_front(x);
}
inline int check(){
if(d.size()<=1) return 0;
return d[0][1]==d[1][3];
}
void sol(int cases) {
int n;
cin>>n;
c.clear();
d.clear();
ans.clear();
vector<int>a(n+1),b(n+1);
for(int i=1;i<=n;++i){
cin>>a[i];
c.push_back(a[i]);
}
for(int i=1;i<=n;++i){
cin>>b[i];
}
for(int i=1;i<=n;++i){
if(i==1){
L[b[i]]=b[n];
R[b[i]]=b[i+1];
}else if(i==n){
L[b[i]]=b[i-1];
R[b[i]]=b[1];
}else{
L[b[i]]=b[i-1];
R[b[i]]=b[i+1];
}
}
for(int i=1;i<=n;++i){
d.push_back({L[a[i]],R[a[i]],1,a[i],a[i]});
}
while(d.size()>1){
int k=d.size();
while(d[0][1]!=d[1][3]){
f2();
}
while(check()){
auto x=d[0];
d.pop_front();
auto y=d[0];
d.pop_front();
d.push_front({x[0],y[1],x[2]+y[2],x[3],y[4]});
}
int s=d[0][2];
while(s--){
ans.push_back(1);
}
while(d.size()>1&&d[0][2]!=1){
d.push_back(d[0]);
d.pop_front();
}
}
for(auto &x:ans){
if(x==1){
c.push_back(c[0]);
c.pop_front();
}else{
auto &y=c[0];
c.pop_front();
c.push_back(c[0]);
c.pop_front();
c.push_front(y);
}
}
while(c[0]!=b[1]){
c.push_back(c[0]);
c.pop_front();
ans.push_back(1);
}
for(auto &x:ans) cout<<x;
cout<<'\n';
}
signed main(){
IOS;
int t=1;
cin>>t;
for(int i=1;i<=t;++i){
sol(i);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5896kb
input:
2 3 1 2 3 2 3 1 4 1 2 3 4 2 1 3 4
output:
1111 21111111
result:
ok Correct. (2 test cases)
Test #2:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
200 3 3 1 2 2 3 1 4 2 4 1 3 2 1 4 3 4 1 4 2 3 2 1 3 4 5 4 3 2 1 5 2 4 5 3 1 5 2 1 5 4 3 5 2 4 1 3 4 4 3 1 2 1 2 4 3 3 1 2 3 3 1 2 4 1 4 2 3 2 1 4 3 4 1 3 2 4 1 4 3 2 3 3 2 1 1 3 2 3 2 3 1 1 3 2 4 1 4 3 2 3 1 2 4 3 1 2 3 1 3 2 3 3 2 1 2 3 1 5 5 1 3 2 4 2 4 5 1 3 4 4 3 1 2 1 4 3 2 4 1 3 4 2 2 4 3 1 3 ...
output:
11111 211211111 221111111 222111211111 22112111111 111111 11111 1121111 221111 11111 21111 221111111 2111 211111 11111111 1121111 22112111111 1111 1111 2111211111111 1121111111 221121111111 2111111 112111111 22211112211111 1111 21121111111 111122111111 1121111111 211111 2111 22112111111 211111 22111...
result:
ok Correct. (200 test cases)
Test #3:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
200 5 5 1 3 4 2 5 3 2 4 1 5 5 1 2 4 3 3 5 4 1 2 5 1 4 5 3 2 2 5 4 3 1 5 1 5 4 3 2 4 5 2 3 1 5 2 3 4 5 1 5 4 3 2 1 5 1 5 2 4 3 5 3 1 2 4 5 1 2 4 3 5 4 2 3 5 1 5 3 2 1 4 5 4 2 3 1 5 5 3 1 2 5 4 2 4 1 3 5 5 5 3 1 4 2 2 5 4 1 3 5 5 4 3 1 2 2 5 4 1 3 5 3 4 5 2 1 3 5 1 4 2 5 4 5 1 3 2 4 2 3 1 5 5 1 3 4 5 ...
output:
21121111111 22112211111 22211211111111 21122111211111111 22211221112111111111 21112111111111 2111122111111111 211211111 2211112211111 2211221112111111 112111111 21122111111 222112211121111111 2221122111211111 11111 2211112211111111 2211221111111 21112111111111 2221112111111 2221122111211111 21122111...
result:
ok Correct. (200 test cases)
Test #4:
score: -100
Time Limit Exceeded
input:
100 5 1 2 5 4 3 2 4 5 3 1 6 6 1 5 2 4 3 1 4 5 6 2 3 3 2 1 3 1 2 3 5 5 3 4 2 1 1 2 3 5 4 10 5 9 4 2 6 10 7 8 3 1 1 3 4 10 5 7 2 9 8 6 10 5 9 10 7 8 3 4 6 2 1 2 7 4 3 10 9 5 8 1 6 8 1 7 4 6 3 5 2 8 3 5 1 4 6 8 7 2 4 2 3 4 1 1 4 2 3 7 3 7 4 6 2 1 5 5 6 7 3 4 1 2 8 2 1 4 7 8 3 6 5 5 2 7 4 3 1 8 6 4 3 2 ...