QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#468513#1281. Longest Common SubsequencezbrcWA 190ms13864kbC++201.1kb2024-07-08 21:14:022024-07-08 21:14:03

Judging History

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

  • [2024-07-08 21:14:03]
  • 评测
  • 测评结果:WA
  • 用时:190ms
  • 内存:13864kb
  • [2024-07-08 21:14:02]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e5+10;
int a1[N],sum1[N],a3[N],b1[N],sum2[N],b3[N];
int T;
int n,m;
int a[N],b[N];
signed main(){
	cin>>T;
	while(T--){
		cin>>n>>m;
		for(int i=1;i<=n;i++)cin>>a[i];
		for(int i=1;i<=m;i++)cin>>b[i];
		int cnt1=0,cnt2=0,cnt3=0,cnt4=0;
		for(int i=1;i<=n;i++){
			sum1[i]=sum1[i-1];
			if(a[i]==2)sum1[i]=sum1[i-1]+1;
			if(a[i]==1)a1[++cnt1]=i;
		}
		for(int i=n;i;i--){
			if(a[i]==3)a3[++cnt2]=i;
		}
//		cnt=0;
		for(int i=1;i<=m;i++){
			sum2[i]=sum2[i-1];
			if(b[i]==2)sum2[i]=sum2[i-1]+1;
			if(b[i]==1)b1[++cnt3]=i;
		}
//		cnt=0;
		for(int i=n;i;i--){
			if(b[i]==3)b3[++cnt4]=i;
		}
		int ans=0;
		a1[0]=b1[0]=0;a3[0]=n+1;b3[0]=m+1;
		for(int i=0,j=-1;i<=min(cnt1,cnt3);i++){
			if(j>=0&&i>=0)ans=max(ans,min(i+j+sum1[a3[j]-1]-sum1[a1[i]],i+j+sum2[b3[j]-1]-sum2[b1[i]]));
			while(a1[i]<a3[j+1]&&b1[i]<b3[j+1]&&j<min(cnt2,cnt4)){
				j++;
//				cout<<a1[i]<<' '<<a3[j]<<'*'<<b1[i]<<' '<<b3[j]<<'\n';
				ans=max(ans,min(i+j+sum1[a3[j]-1]-sum1[a1[i]],i+j+sum2[b3[j]-1]-sum2[b1[i]]));
			}
		}
		cout<<ans<<'\n';
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 13788kb

input:

3
3 3
1 2 3
1 2 3
3 3
1 1 1
1 1 2
3 3
1 3 2
1 2 3

output:

3
2
2

result:

ok 3 tokens

Test #2:

score: -100
Wrong Answer
time: 190ms
memory: 13864kb

input:

139889
1 10
2
2 1 2 2 3 1 1 2 3 3
7 1
3 2 3 3 1 1 2
2
6 1
2 1 3 1 1 1
1
8 7
3 1 3 3 2 2 3 1
3 2 2 1 3 3 3
10 3
3 2 1 1 2 2 1 1 1 1
3 1 1
5 2
1 2 1 3 1
1 2
1 4
1
3 3 3 3
7 2
3 1 2 1 2 2 3
3 2
6 2
3 1 1 2 1 3
1 3
1 4
1
3 1 1 3
4 2
2 3 2 3
1 3
1 8
1
1 1 3 1 3 3 3 1
4 1
1 3 3 3
1
10 10
3 1 2 1 2 2 2 2 1...

output:

1
2
2
4
2
3
0
3
3
1
2
1
2
6
1
0
1
3
4
3
4
3
1
1
1
0
2
3
4
4
4
4
2
2
2
3
2
1
3
1
1
1
3
1
1
4
3
2
1
3
1
5
1
4
3
1
4
1
2
4
3
1
2
4
4
2
2
1
1
1
3
4
2
1
3
2
2
4
3
2
2
1
5
2
3
1
1
4
3
3
5
2
1
4
1
3
2
2
2
2
3
5
3
2
1
3
3
4
3
3
2
2
0
0
4
4
2
2
0
5
1
5
2
3
3
4
2
0
1
1
5
1
3
3
3
2
3
3
2
1
2
2
3
2
1
1
3
5
2
3
...

result:

wrong answer 2nd words differ - expected: '1', found: '2'