Submission #1120106

#TimeUsernameProblemLanguageResultExecution timeMemory
1120106ezzzayBouquet (EGOI24_bouquet)C++14
46 / 100
3100 ms9048 KiB
#include<bits/stdc++.h> using namespace std; #define itn long long #define int long long #define ff first #define ss second #define pb push_back const int N=3e5+5; int l[N],r[N]; int dp[N]; int p[N]; int n; void fun(){ int ans=0; for(int i=1;i<=n;i++){ dp[i]=1; for(int j=max(0LL,i-2);j<i;j++){ if(r[j]+j>=i)continue; if(i-l[i]<=j)continue; dp[i]=max(dp[i],dp[j]+1); } if(i-3>=0){ dp[i]=max(dp[i],p[i-3]+1); } ans=max(ans,dp[i]); p[i]=max(dp[i],p[i-1]); } cout<<ans; } signed main(){ cin>>n; bool u=0; for(int i=1;i<=n;i++){ cin>>l[i]>>r[i]; if(l[i]>2 or r[i]>2)u=1; } if(u==1){ int ans=0; for(int i=1;i<=n;i++){ dp[i]=1; for(int j=0;j<i;j++){ if(r[j]+j>=i)continue; if(i-l[i]<=j)continue; dp[i]=max(dp[i],dp[j]+1); } ans=max(ans,dp[i]); } cout<<ans; return 0; } if(u==0){ fun(); return 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...