90分,WA on #2

P1439 【模板】最长公共子序列

river_wind @ 2024-07-30 09:44:20

#include<iostream>
#include <climits>
using namespace std;
int n,ans;
int a[100005];
int b[100005];
int c[100005];
int dp[100005];
int f[100005];
int main(){
    cin>>n;
    for(int i = 1;i<=n;i++){
        cin>>a[i];
        c[a[i]] = i;
    }
    for(int i = 1;i<=n;i++){
        cin>>b[i];
        b[i] = c[b[i]];
    }
    for(int i = 1;i<=n;i++){
        f[i] = INT_MAX;
    }
    f[0] = INT_MIN;
    for(int i = 1;i<=n;i++){
        *lower_bound(f+1,f+n+1,b[i]) = b[i];
    }
    cout<<lower_bound(f+1,f+n+2,INT_MAX)-f-1;
}

by cao691234 @ 2024-07-30 20:24:03

要加一个如果两序列相等,输出n的特判


by tanghaohan12 @ 2024-08-20 16:23:44

把-1给改成-2

就可以将第1个测试点变成WA

其他全部AC


by tanghaohan12 @ 2024-08-20 16:24:42

f[0]改为f[1]

要不然就10分


|