fork(1) download
  1.  
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <fstream>
  6. using namespace std;
  7.  
  8. int main(void)
  9. {
  10. ifstream fin("262144.in");
  11. ofstream fout("262144.out");
  12. int n, res = 0;
  13. fin >> n;
  14. vector<int> A(n);
  15. vector<vector<int>> range(2, vector<int>(n+2, -1));
  16. for(int i = 0;i < n;i++)
  17. {
  18. fin >> A[i];
  19. res = max(res, A[i]);
  20. }
  21.  
  22. for(int k = 1;k <= 65;k++)
  23. {
  24. for(int i = 0;i < n;i++)
  25. {
  26. if(A[i] == k-1) range[0][i] = i;
  27. }
  28. for(int i = 0;i < n;i++)
  29. {
  30. if(range[0][i] != -1)
  31. {
  32. if(range[0][range[0][i]+1] != -1)
  33. {
  34. res = max(res, k);
  35. range[1][i] = range[0][range[0][i]+1];
  36. }
  37. }
  38. }
  39. range[0] = range[1];
  40. range[1].clear(); range[1].resize(n+2, -1);
  41. }
  42. fout << res << "\n";
  43. }
Runtime error #stdin #stdout #stderr 0s 3412KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc