QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#358750 | #4629. Longest Increasing Subsequence | Kevin5307 | WA | 0ms | 5712kb | C++20 | 1.9kb | 2024-03-19 23:35:18 | 2024-03-19 23:35:18 |
Judging History
answer
//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
ll a[100100];
ll dp[100100][62];
ll val[100100];
array<ll,3> calc(ll len,int d)
{
if(len==1) return {0,0,0};
if(len==2)
{
if(!d) return {0,1,1};
return {1,1,0};
}
if(len==3)
{
if(d==1)
return {1,2,2};
return {2,2,0};
}
array<ll,3> a1=calc(len/2,d-1),a2=calc(len-len/2,d-1);
return {a1[0]+a2[0],max({a1[0]+a2[1],a1[1]+a2[2]}),a1[2]+a2[2]};
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=2;i<=n;i++)
{
array<ll,3> tmp=calc(a[i]-a[i-1],__lg(a[i]-a[i-1]-1));
val[i]=max({tmp[0],tmp[1],tmp[2]});
}
for(int i=n;i>1;i--)
for(int j=0;j<=61;j++)
{
dp[i][j]=max(dp[i+1][j],dp[i][j]);
if((1ll<<j)<=a[i]-a[i-1]-1)
{
if((1ll<<j+1)-1<=a[i]-a[i-1]-1)
{
dp[i][j]=max(dp[i][j],dp[i+1][j]+(1ll<<j));
if((1ll<<j+1)-1==a[i]-a[i-1]-1)
for(int j2=j+1;j2<=61;j2++)
dp[i][j]=max(dp[i][j],dp[i+1][j2]+(1ll<<j));
}
else
{
dp[i][j]=max(dp[i][j],dp[i+1][j]+a[i]-a[i-1]-(1ll<<j));
for(int j2=j;j2<=61;j2++)
dp[i][j-1]=max(dp[i][j-1],dp[i+1][j2]+val[i]);
}
}
}
ll ans=0;
for(int i=2;i<=n;i++)
for(int j=0;j<=61;j++)
ans=max(ans,i-1+dp[i][j]);
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
7 7 41 53 58 75 78 81
output:
22
result:
ok single line: '22'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 5712kb
input:
8 174 223 259 368 618 738 893 1810
output:
798
result:
wrong answer 1st lines differ - expected: '671', found: '798'