fork download
  1. // ඞඞඞඞඞඞ you sus
  2. #include <bits/stdc++.h>
  3.  
  4. #define __builtin_popcount __builtin_popcountll
  5. #define BIT(x, i) (((x)>> (i))& 1)
  6. #define MASK(x) (1LL<< (x))
  7. #define sqr(x) ((x)* (x))
  8. #define MOD 1000000007
  9. #define template(i) for(long long i= 1; i<= n; i++)
  10.  
  11. using namespace std;
  12.  
  13. typedef long long ll;
  14.  
  15. template<class X,class Y>
  16. void minimize(X &x,const Y y) {
  17. if (x>y) x= y;
  18. }
  19. template<class X,class Y>
  20. void maximize(X &x,const Y y) {
  21. if (x<y) x= y;
  22. }
  23. template<class T>
  24. T Abs(const T x) {
  25. return (x<0?-x:x);
  26. }
  27.  
  28. template <class T>
  29. void Mod(T &t) {
  30. if(t>= MOD) t-= MOD;
  31. }
  32.  
  33. template <class X, class Y>
  34. ll Gcd(const X a, const Y b){
  35. if(b== 0) return a;
  36. else return Gcd(b, a% b);
  37. }
  38.  
  39. template <class X, class Y>
  40. ll Lcm(const X a, const Y b){
  41. return ((a*b)/gcd(a, b));
  42. }
  43.  
  44. template <class X, class Y>
  45. void Add(X &x, const Y y){
  46. if((x+= y)>= MOD) x-= MOD;
  47. }
  48.  
  49. const int maxm= (int)1e6+ 3, maxn= (int)1e5 +3, maxpst= (int)17e5, maxb= (int)1e3+ 3;
  50.  
  51. const ll INF= (ll)1e18+ 3;
  52.  
  53. vector<ll> adj[maxb];
  54.  
  55. vector<ll> topo;
  56. ll n, a[maxb], f[maxb], ans= 0, vis[maxb];
  57.  
  58. void Dfs(ll u){
  59. vis[u]= 1;
  60. for(long long i= 0; i< adj[u].size(); i++){
  61. ll v= adj[u][i];
  62. if(!vis[v])
  63. Dfs(v);
  64. }
  65. topo.push_back(u);
  66. }
  67.  
  68. void printans(){
  69. cout<< ans;
  70. }
  71.  
  72. void solve(){
  73. for(int i= 1; i<= n; i++){
  74. for(int j= 1; j<= n; j++){
  75. for(int k= 1; k<= n; k++){
  76. if((i== j)|| (i== k)|| (j== k)) continue;
  77. if(a[i]+ a[j]== a[k]){
  78. adj[i].push_back(k);
  79. adj[j].push_back(k);
  80. }
  81. }
  82. }
  83. }
  84. for(long long i= 1; i<= n; i++){
  85. if(vis[i]== 0){
  86. Dfs(i);
  87. }
  88. }
  89. reverse(topo.begin(), topo.end());
  90. for(long long i= 1; i<= n; i++){
  91. f[i]= 1;
  92. }
  93. for(long long i= 0; i< n; i++){
  94. ll u= topo[i];
  95. for(long long j= 0; j< adj[u].size(); j++){
  96. ll v= adj[u][j];
  97. maximize(f[v], f[u]+ 1);
  98. }
  99. maximize(ans, f[u]);
  100. }
  101. }
  102.  
  103. void input(){
  104. cin>> n;
  105. for(long long i= 1; i<= n; i++){
  106. cin>> a[i];
  107. }
  108. solve();
  109. printans();
  110. }
  111.  
  112. int main()
  113.  
  114. { ios_base::sync_with_stdio(0);cin.tie(0);
  115. #define task ""
  116. if(fopen(task".inp", "r")){
  117. freopen(task".inp", "r", stdin);
  118. freopen(task".out", "w", stdout);
  119. }
  120. if(fopen("task.inp", "r")){
  121. freopen("task.inp", "r", stdin);
  122. freopen("task.out", "w", stdout);
  123. }
  124. input();
  125. return 0;
  126. }
  127.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty