fork(1) download
  1. #include <bits/stdc++.h>
  2. #define endl '\n'
  3.  
  4. using namespace std;
  5.  
  6. const int N = 1<<17;
  7.  
  8. struct xorshift32 {
  9. unsigned x,y,z,w;
  10. xorshift32(): x(123456789), y(2378257), z(7777777), w(85715718) {}
  11. unsigned next() {
  12. unsigned t=x^(x<<11);
  13. x=y;y=z;z=w;
  14. return w=w^(w>>19)^t^(t>>8);
  15. }
  16. unsigned next(unsigned n) {
  17. return next()%n;
  18. }
  19. int next(int a, int b) {
  20. return a+next(b-a+1);
  21. }
  22. };
  23.  
  24. int tests,current_case;
  25. int n,a[N];
  26. long long ans;
  27. xorshift32 rng;
  28.  
  29. void message(int current_case) {
  30. //cerr<<"Case "<<current_case<<" solved!"<<endl;
  31. fprintf(stderr, "Case %d solved!\n", current_case);
  32. }
  33.  
  34.  
  35.  
  36. int main() {
  37. //ios_base::sync_with_stdio(false);
  38. //cin.tie(NULL);
  39. int i,j;
  40.  
  41. tests=1;
  42. //scanf("%d", &tests);
  43. //cin>>tests;
  44. for(current_case=1;current_case<=tests;current_case++) {
  45. scanf("%d", &n);
  46. for(i=1;i<=n;i++) {
  47. scanf("%d", &a[i]);
  48. }
  49. sort(a+1,a+1+n);
  50. while(clock()<=1.7*CLOCKS_PER_SEC) {
  51. if(n>1000) {
  52. i=1+rng.next(n-1000,n);
  53. j=1+rng.next(n-1000,n-1);
  54. if(j>=i) ++j;
  55. ans=max(ans,(a[i]|a[j])*1ll*(a[i]&a[j]));
  56. }
  57. else {
  58. i=1+rng.next(1,n);
  59. j=1+rng.next(1,n-1);
  60. if(j>=i) {
  61. ++j;
  62. }
  63. ans=max(ans,(a[i]|a[j])*1ll*(a[i]&a[j]));
  64. }
  65. }
  66. printf("%lld\n", ans);
  67.  
  68. MESSAGE:
  69. message(current_case);
  70. }
  71.  
  72. return 0;
  73. }
Runtime error #stdin #stdout 0s 3984KB
stdin
Standard input is empty
stdout
Standard output is empty