QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#597976#4422. Two Permutationshuaxiamengjin#WA 1754ms44296kbC++141.1kb2024-09-28 19:47:492024-09-28 19:47:53

Judging History

你现在查看的是最新测评结果

  • [2024-09-28 19:47:53]
  • 评测
  • 测评结果:WA
  • 用时:1754ms
  • 内存:44296kb
  • [2024-09-28 19:47:49]
  • 提交

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<=n;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: 1754ms
memory: 44296kb

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
4
48
8
10
12
7
8
72
80
44
48
26
28
30
16
34
36
38
40
42
22
23
48
200
26
54
56
116
60
62
32
66
68
280
72
74
76
156
160
41
168
43
176
180
46
47
384
196
0
4
8
3
8
20
2
4
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 2nd lines differ - expected: '2', found: '4'