QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#468528 | #1281. Longest Common Subsequence | zbrc | WA | 204ms | 13908kb | C++20 | 1.1kb | 2024-07-08 21:21:44 | 2024-07-08 21:21:44 |
Judging History
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]++;
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]++;
if(b[i]==1)b1[++cnt3]=i;
}
// cnt=0;
for(int i=m;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=0;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]&&b1[i]<b3[j]&&j<=min(cnt2,cnt4)){
ans=max(ans,min(i+j+sum1[a3[j]-1]-sum1[a1[i]],i+j+sum2[b3[j]-1]-sum2[b1[i]]));
j++;
}
j--;
}
cout<<ans<<'\n';
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 13852kb
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: 204ms
memory: 13908kb
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 1 1 4 2 2 0 1 2 1 1 1 1 6 1 0 1 2 2 3 4 4 1 1 1 0 2 2 3 4 3 1 1 3 2 1 2 1 3 1 1 1 3 1 1 1 3 2 1 3 1 4 1 2 2 1 3 1 1 2 3 1 2 3 4 2 2 1 1 1 2 3 3 2 1 1 2 3 1 2 2 1 5 2 4 2 1 2 3 2 5 2 1 3 1 3 1 2 1 2 2 4 2 2 0 1 1 3 2 3 2 2 0 0 2 3 1 2 0 4 1 4 1 1 3 1 1 0 1 1 1 1 3 2 2 2 3 3 3 1 2 2 3 2 1 1 3 3 2 3 ...
result:
wrong answer 31st words differ - expected: '4', found: '3'