Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- const int mxn = 1e6+10;
- const int inf = 1e9;
- int a[mxn], dp[mxn][70];
- int main() {
- ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
- freopen("262144.in", "r", stdin);
- freopen("262144.out", "w", stdout);
- int n; cin>>n;
- for(int i=0; i<n; i++) cin>>a[i];
- for(int i=0; i<n+3; i++) for(int j=0; j<70; j++) dp[i][j] = -1;
- for(int i=0; i<n; i++) dp[i][a[i]] = i;
- for(int i=n-2; i>=0; i--) {
- for(int j=1; j<70; j++) {
- if(dp[i][j-1]!=-1) dp[i][j] = dp[dp[i][j-1]+1][j-1];
- }
- }
- int mx = 0;
- for(int i=0; i<n; i++) for(int j=1; j<70; j++) if(dp[i][j]!=-1) mx = max(mx, j);
- cout << mx << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement