QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#468520 | #1281. Longest Common Subsequence | zbrc | WA | 216ms | 13848kb | C++20 | 1.1kb | 2024-07-08 21:16:29 | 2024-07-08 21:16:31 |
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]=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=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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 13848kb
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: 216ms
memory: 13840kb
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 2 1 2 1 2 6 1 0 1 3 4 3 4 4 1 1 1 0 2 3 3 3 3 4 2 2 2 3 2 1 3 1 1 1 3 1 1 4 3 2 1 3 1 5 1 4 2 1 3 1 2 4 3 1 2 3 4 2 2 1 1 1 2 3 2 1 3 2 2 4 3 2 2 1 5 2 2 1 1 3 3 3 5 2 1 3 1 3 2 2 2 2 3 4 2 2 1 3 3 3 2 3 2 2 0 0 4 4 1 1 0 5 1 4 2 3 3 4 2 0 1 1 5 1 3 2 3 2 3 3 3 1 2 2 3 2 1 1 3 4 2 3 ...
result:
wrong answer 2nd words differ - expected: '1', found: '2'