fork download
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace __gnu_pbds;
  5. using namespace std;
  6. typedef long long ll;
  7. typedef vector <ll> vll;
  8. typedef set <ll> sll;
  9. typedef vector <vector<ll>> vvll;
  10. typedef set<pair<ll,ll>> spll;
  11. typedef vector <bool> vbl;
  12. ll LMA=LLONG_MAX;
  13. ll LMI=LLONG_MIN;
  14.  
  15. template<typename T>
  16. using ordered_set = tree<
  17. T,
  18. null_type,
  19. less<T>,
  20. rb_tree_tag,
  21. tree_order_statistics_node_update>;
  22.  
  23. int main()
  24. {
  25. ios_base::sync_with_stdio(false);
  26. cin.tie(0);
  27.  
  28. ll t=1;
  29. // cin>>t;
  30.  
  31. while (t--)
  32. {
  33. ll n;
  34. cin>>n;
  35. vll v(n+1);
  36. for (ll i=1;i<=n;i++)
  37. {
  38. cin>>v[i];
  39. }
  40. if (n==1)
  41. {
  42. cout<<v[1]<<"\n";
  43. return 0;
  44. }
  45. if (n>=15)
  46. {
  47. cout<<"32767"<<"\n";
  48. } else
  49. {
  50. ll answer=0;
  51. for (ll i=1;i<=n;i++)
  52. {
  53. answer |= v[i];
  54. }
  55. for (ll i=1;i<=(n-1);i++)
  56. {
  57. for (ll j=i+1;j<=n;j++)
  58. {
  59. vll temp=v;
  60. temp[i] ^= (1<<15)-1;
  61. temp[j] ^= (1<<15)-1;
  62. ll res=0;
  63. for (ll k=1;k<=n;k++)
  64. {
  65. res |= temp[k];
  66. }
  67. answer=max(answer,res);
  68. }
  69. }
  70. cout<<answer<<"\n";
  71. }
  72. }
  73.  
  74. return 0;
  75. }
Runtime error #stdin #stdout #stderr 0.01s 5288KB
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