fork download
  1. #include<bits/stdc++.h>
  2. #define M 5004
  3. using namespace std;
  4.  
  5. int n, a[M], d[M], dp[M][M];
  6.  
  7. int main()
  8. {
  9. ios_base::sync_with_stdio(0);
  10. cin.tie(0); cout.tie(0);
  11.  
  12. cin >> n;
  13. for(int i = 1; i <= n; i++)
  14. cin >> a[i];
  15. for(int i = 1; i < n; i++)
  16. d[i] = a[i + 1] - a[i];
  17. int ans = 0;
  18. for(int i = 1; i < n - 4; i++)
  19. {
  20. for(int j = i + 4; j < n; j++)
  21. {
  22. if(d[i] == d[j])
  23. {
  24. dp[i][j] = min(dp[i - 1][j - 1] + 1, j - i - 1);
  25. ans = max(ans, dp[i][j]);
  26. }
  27. }
  28. }
  29. if(ans >= 4) cout << ans + 1;
  30. else cout << 0;
  31. }
  32.  
Success #stdin #stdout 0.01s 5268KB
stdin
30
25 27 30 34 39 45 52 60 69 79 69 60 52 45 39 34 30 26 22 18
82 78 74 70 66 67 64 60 65 80
stdout
5