QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#503629 | #4629. Longest Increasing Subsequence | tarjen# | WA | 0ms | 3612kb | C++20 | 1.6kb | 2024-08-03 21:22:23 | 2024-08-03 21:22:24 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=65;
typedef array<int,N> info;
info operator+(info x,info y){
for(int i=0;i<N;i++)x[i]+=y[i];
return x;
}
void mv(info &x){
for(int i=N-1;i>=1;i--)x[i]=x[i-1];
x[0]=1;
}
map<pair<int,bool>,info>ma;
int flag=0;
info dfs(int len,bool left){
if(ma.find({len,left})!=ma.end())return ma[{len,left}];
int mid=(1+len)/2;
info p{0};
if(mid>=3)p=dfs(mid,left);
if(len-mid+1>=3)p=p+dfs(len-mid+1,false);
mv(p);
if(len==4&&left)flag+=1,p[1]+=1;
if(len==6&&left)flag+=2,p[2]+=2;
// cout<<"len="<<len<<endl;
// for(int i=0;i<5;i++)cout<<p[i]<<" \n"[i==4];
return ma[{len,left}]=p;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
vector<int> a(n+1);
info dp{0};
dp[0]=1;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<n;i++){
ma.clear();
flag=0;
info now{0},dp2{0};
if(a[i+1]-a[i]+1>=3)now=dfs(a[i+1]-a[i]+1,true);
mv(now);
// cout<<"i="<<i<<endl;
int z=0;
for(int i=0;i<N;i++)if(now[i])z=i;
for(int j=0;j<N;j++)if(dp[j]){
for(int k=j;k<N;k++)dp2[k]=max(dp2[k],dp[j]+(k==z?(j<k?now[k]:now[k]-flag):now[k]));
}
dp=dp2;
// cout<<"flag="<<flag<<endl;
// for(int j=0;j<5;j++){
// cout<<now[j]<<" \n"[j==4];
// }
// cout<<"i="<<i<<" ";;for(int j=0;j<5;j++)cout<<dp[j]<<" ";;cout<<endl;
}
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: 0ms
memory: 3612kb
input:
7 7 41 53 58 75 78 81
output:
21
result:
wrong answer 1st lines differ - expected: '22', found: '21'