QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#503576#4629. Longest Increasing Subsequencetarjen#WA 6ms4304kbC++201.6kb2024-08-03 20:12:152024-08-03 20:12:16

Judging History

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

  • [2024-08-03 20:12:16]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:4304kb
  • [2024-08-03 20:12:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=65;
struct Matrix{
    int a[N][N];
    Matrix(){
        memset(a,0,sizeof(a));
    }
};
Matrix operator+(Matrix a, Matrix b) {
    Matrix c;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            for(int k=0;k<N;k++)c.a[i][k]=max(c.a[i][k],a.a[i][j]+b.a[j][k]);
        }
    }
    return c;
}
void mv(Matrix &a){
    for(int i=N-1;i>=1;i--){
        for(int j=N-1;j>=1;j--)a.a[i][j]=a.a[i-1][j-1];
    }
    for(int i=0;i<N;i++)a.a[0][i]=a.a[i][0]=0;
}
void gmax(int &x,int y){
    if(y>x)x=y;
}
map<int,Matrix> ma;
Matrix dfs(int len){
    if(ma.find(len)!=ma.end())return ma[len];
    int mid=(1+len)/2;
    Matrix p1,p2;
    if(mid>=3)p1=dfs(mid);
    if(len-mid+1>=3)p2=dfs(len-mid+1);
    mv(p1),mv(p2);
    for(int i=0;i<N;i++){
        for(int j=0;j<=i;j++)gmax(p2.a[0][i],p2.a[j][i]+1);
    }
    return p1+p2;
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    vector<int> a(n+1);
    vector<int> dp(N,0);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<n;i++){
        vector<int> dp2(N,0);
        Matrix now;
        if(a[i+1]-a[i]+1>=3)now=dfs(a[i+1]-a[i]+1);
        mv(now);
        for(int i=0;i<N;i++){
            for(int j=0;j<=i;j++)gmax(now.a[0][i],now.a[j][i]+1);
        }
        for(int j=0;j<N;j++){
            for(int k=j;k<N;k++)gmax(dp2[k],dp[j]+now.a[j][k]);
        }
        dp=dp2;
    }
    dp[0]++;
    int ans=0;
    for(int i=0;i<N;i++)if(dp[i])ans=max(ans,dp[i]);
    cout<<ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 4304kb

input:

7
7 41 53 58 75 78 81

output:

43

result:

wrong answer 1st lines differ - expected: '22', found: '43'