fork download
  1. import java.io.BufferedInputStream;
  2. import java.io.InputStream;
  3. import java.io.OutputStream;
  4. import java.io.PrintWriter;
  5.  
  6. /**
  7.  * @author khokharnikunj8
  8.  */
  9.  
  10. public class Main {
  11. public static void main(String[] args) {
  12. new Thread(null, new Runnable() {
  13. public void run() {
  14. new Main().solve();
  15. }
  16. }, "1", 1 << 26).start();
  17. }
  18.  
  19. void solve() {
  20. InputStream inputStream = System.in;
  21. OutputStream outputStream = System.out;
  22. ScanReader in = new ScanReader(inputStream);
  23. PrintWriter out = new PrintWriter(outputStream);
  24. MAXOR solver = new MAXOR();
  25. solver.solve(1, in, out);
  26. out.close();
  27. }
  28.  
  29. static class MAXOR {
  30. public void solve(int testNumber, ScanReader in, PrintWriter out) {
  31. int n = in.scanInt();
  32. int[] ar = new int[n];
  33. for (int i = 0; i < n; i++) ar[i] = in.scanInt();
  34. boolean[] SOSdp1 = new boolean[1 << 20];
  35. for (int i : ar) SOSdp1[i] = true;
  36. for (int i = 0; i < 20; ++i)
  37. for (int mask = 0; mask < (1 << 20); ++mask) {
  38. if ((mask & 1 << i) != 0)
  39. SOSdp1[mask ^ (1 << i)] |= SOSdp1[mask];
  40. }
  41. int[] SOSdp2 = new int[1 << 20];
  42. for (int i = 0; i < (1 << 20); i++) if (SOSdp1[i]) SOSdp2[i] = i;
  43. for (int i = 0; i < 20; ++i)
  44. for (int mask = 0; mask < (1 << 20); ++mask) {
  45. if ((mask & 1 << i) != 0)
  46. SOSdp2[mask] = Math.max(SOSdp2[mask ^ (1 << i)], SOSdp2[mask]);
  47. }
  48. int ans = 0;
  49. for (int i = 0; i < n; i++) {
  50. ans = Math.max(ans, SOSdp2[((1 << 20) - 1) ^ ar[i]] | ar[i]);
  51. }
  52. out.println(ans);
  53.  
  54.  
  55. }
  56.  
  57. }
  58.  
  59. static class ScanReader {
  60. private byte[] buf = new byte[4 * 1024];
  61. private int index;
  62. private BufferedInputStream in;
  63. private int total;
  64.  
  65. public ScanReader(InputStream inputStream) {
  66. in = new BufferedInputStream(inputStream);
  67. }
  68.  
  69. private int scan() {
  70. if (index >= total) {
  71. index = 0;
  72. try {
  73. total = in.read(buf);
  74. } catch (Exception e) {
  75. e.printStackTrace();
  76. }
  77. if (total <= 0) return -1;
  78. }
  79. return buf[index++];
  80. }
  81.  
  82. public int scanInt() {
  83. int integer = 0;
  84. int n = scan();
  85. while (isWhiteSpace(n)) n = scan();
  86. int neg = 1;
  87. if (n == '-') {
  88. neg = -1;
  89. n = scan();
  90. }
  91. while (!isWhiteSpace(n)) {
  92. if (n >= '0' && n <= '9') {
  93. integer *= 10;
  94. integer += n - '0';
  95. n = scan();
  96. }
  97. }
  98. return neg * integer;
  99. }
  100.  
  101. private boolean isWhiteSpace(int n) {
  102. if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
  103. else return false;
  104. }
  105.  
  106. }
  107. }
  108.  
  109.  
Success #stdin #stdout 0.18s 39452KB
stdin
5
9 8 1 6 2
stdout
15