QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#597980 | #4422. Two Permutations | huaxiamengjin# | WA | 1758ms | 44680kb | C++14 | 1.2kb | 2024-09-28 19:50:12 | 2024-09-28 19:50:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int NN=998244353;
int a[300300],b[300300],c[600600];
int aa[300300],bb[300300];
int f[300300][2],g[300300][2];
vector<int>d[300300];
int n,col[300300];
void solve(){
cin>>n;
for (int i=1;i<=2*n+1;i++)d[i].clear();
for (int i=1;i<=n;i++)
cin>>a[i],aa[a[i]]=i;aa[n+1]=n+1;a[n+1]=n+1;
for (int i=1;i<=n;i++)
cin>>b[i],bb[b[i]]=i;bb[n+1]=n+1;b[n+1]=n+1;
for (int i=1;i<=2*n;i++)
cin>>c[i],d[c[i]].push_back(i),f[i][0]=f[i][1]=g[i][0]=g[i][1]=0;
d[n+1].push_back(2*n+1);
f[2*n+1][0]=1,f[2*n+1][1]=1;g[2*n+1][0]=n+1,g[2*n+1][1]=n+1;
for (int i=2*n;i;i--){
for (auto j:d[a[aa[c[i]]+1]])
if(j>i){
int t2=g[j][0],fl=1;
for (int k=j-1;k>i;k--)
if(b[bb[t2]-1]==c[k])t2=c[k];
else {fl=0;break;}
if(fl==1)f[i][0]=(f[i][0]+f[j][0])%NN,g[i][0]=t2;
}
for (auto j:d[b[bb[c[i]]+1]])
if(j>i){
int t2=g[j][1],fl=1;
for (int k=j-1;k>i;k--)
if(a[aa[t2]-1]==c[k])t2=c[k];
else {fl=0;break;}
if(fl==1)f[i][1]=(f[i][1]+f[j][1])%NN,g[i][1]=t2;
}
}
cout<<(f[1][0]+f[1][1])%NN<<"\n";
}
signed main(){
int T;cin>>T;
while(T--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1758ms
memory: 44680kb
input:
282 1000 434 697 735 906 614 835 227 800 116 98 776 601 110 371 262 452 608 368 719 717 241 572 203 410 440 749 604 457 516 637 488 691 841 493 418 307 745 499 833 789 819 179 357 288 129 954 29 391 80 389 771 613 653 747 928 570 518 1000 547 587 727 778 669 554 426 899 256 681 515 532 409 677 533 3...
output:
4 2 16 2 2 2 1 1 8 8 4 4 2 2 2 1 2 2 2 2 2 1 1 2 8 1 2 2 4 2 2 1 2 2 8 2 2 2 4 4 1 4 1 4 4 1 1 8 4 0 4 4 1 2 4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
wrong answer 58th lines differ - expected: '2', found: '0'