fork download
  1. //ojou kawayo no.1
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define tsk "fct052_262144"
  5. #define pb push_back
  6. #define pf push_front
  7. #define fi first
  8. #define se second
  9. #define Ningen_sama signed
  10. #define tachi main()
  11. #define __builtin_popcount __builtin_popcountll
  12. #define el cout<<'\n'
  13. #define all(a) a.begin(),a.end()
  14. #define invAll(a) a.rbegin(),a.rend()
  15. #define sz(a) ((int)a.size())
  16. #define BIT(x, k) (1ll&((x) >> (k)))
  17. #define mem(a,x) memset(a,x,sizeof(a))
  18. #define debug(x) cout << #x << " = " << x << '\n'
  19. #define execute cerr << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << "s"
  20. #define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
  21. #define FORD(i, l, r) for(int i = (l); i >= (r); --i)
  22. #define REP(i, n) for(int i = 0; i < (n); ++i)
  23. //#define int long long
  24.  
  25. template<class T> bool maximize(T& u, T v){if(u >= v) return false;return u = v, true;}
  26. template<class T> bool minimize(T& u, T v){if(u <= v) return false;return u = v, true;}
  27.  
  28. using pii = pair<int, int>;
  29. using ll = long long;
  30. using vi = vector<int>;
  31. using vpii = vector<pair<int, int>>;
  32.  
  33. #define inf32 0x3f3f3f3f
  34. #define inf64 0x3f3f3f3f3f3f3f3f
  35. const int maxn = 262144 + 5;
  36. const int N = 5e3 + 5;
  37. const int base = 31;
  38. const ll mod = 1e9 + 7;
  39. const ll need = 67108863;
  40. const int vc = 2e9 + 1;
  41. const ll INF18 = 4557430888798830399;
  42. const ll LOG = 20;
  43. const double eps = 1e-9;
  44. const int BLOCK = 447;
  45. const int dx[4] = {1, 0, -1, 0};
  46. const int dy[4] = {0, -1, 0, 1};
  47.  
  48. mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
  49. #define rand rd
  50. inline long long Rand(long long L, long long R) {
  51. if(L>R) return 0;
  52. return L + rd() % (R - L + 1);
  53. }
  54.  
  55. inline ll add(ll x, ll y){x+=y;if(x>=mod) x-=mod;if(x<0) x+=mod;return x;}
  56. inline ll mult(ll x, ll y){return 1LL * x * y % mod;}
  57.  
  58. int n;
  59. int a[maxn];
  60. int dp[60][maxn];
  61.  
  62. inline void init(){
  63.  
  64. }
  65.  
  66. inline void input(){
  67. cin >> n;
  68. FOR(i, 1, n) cin >> a[i];
  69. }
  70.  
  71. inline void solve(){
  72. mem(dp, -1);
  73. FOR(i, 1, n) dp[a[i]][i] = i + 1;
  74. int ans = *max_element(a + 1, a + 1 + n);
  75. FOR(v, 2, 59){
  76. FOR(i, 1, n){
  77. if(dp[v][i] == -1 && dp[v - 1][i] != -1 && dp[v - 1][dp[v - 1][i]] != -1) dp[v][i] = dp[v - 1][dp[v - 1][i]];
  78. if(dp[v][i] != -1) ans = max(ans, v);
  79. }
  80. }
  81.  
  82. cout << ans;
  83. }
  84.  
  85. Ningen_sama tachi{
  86. //konnakiri~~
  87. if(fopen(tsk".inp","r")){
  88. freopen(tsk".inp","r",stdin);
  89. freopen(tsk".out","w",stdout);
  90. }
  91. ios_base::sync_with_stdio(false);
  92. cin.tie(0); cout.tie(0);
  93.  
  94. int Yodayo = 1;
  95.  
  96. //cin >> Yodayo;
  97. //init();
  98.  
  99. while(Yodayo--){
  100. input();
  101. solve();
  102. }
  103.  
  104. //execute;
  105. }
  106. //otsunakiri~~
  107.  
Success #stdin #stdout 0.01s 65824KB
stdin
Standard input is empty
stdout
Standard output is empty