結果

問題 No.2071 Shift and OR
ユーザー tentententen
提出日時 2022-09-20 08:43:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 2,155 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 77,892 KB
実行使用メモリ 39,836 KB
最終ジャッジ日時 2024-06-01 16:50:58
合計ジャッジ時間 6,706 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
39,004 KB
testcase_01 AC 84 ms
39,264 KB
testcase_02 AC 96 ms
39,580 KB
testcase_03 AC 92 ms
39,452 KB
testcase_04 AC 94 ms
39,620 KB
testcase_05 AC 59 ms
38,600 KB
testcase_06 AC 94 ms
39,476 KB
testcase_07 AC 91 ms
39,296 KB
testcase_08 AC 101 ms
39,320 KB
testcase_09 AC 91 ms
39,284 KB
testcase_10 AC 91 ms
39,700 KB
testcase_11 AC 55 ms
38,064 KB
testcase_12 AC 58 ms
38,528 KB
testcase_13 AC 55 ms
38,380 KB
testcase_14 AC 88 ms
38,892 KB
testcase_15 AC 56 ms
38,108 KB
testcase_16 AC 96 ms
39,564 KB
testcase_17 AC 54 ms
38,480 KB
testcase_18 AC 86 ms
39,012 KB
testcase_19 AC 56 ms
38,212 KB
testcase_20 AC 55 ms
38,652 KB
testcase_21 AC 56 ms
39,012 KB
testcase_22 AC 53 ms
38,728 KB
testcase_23 AC 54 ms
37,112 KB
testcase_24 AC 53 ms
36,968 KB
testcase_25 AC 54 ms
37,076 KB
testcase_26 AC 54 ms
36,892 KB
testcase_27 AC 53 ms
37,032 KB
testcase_28 AC 53 ms
36,916 KB
testcase_29 AC 52 ms
36,648 KB
testcase_30 AC 104 ms
39,544 KB
testcase_31 AC 106 ms
39,456 KB
testcase_32 AC 107 ms
39,836 KB
testcase_33 AC 113 ms
39,772 KB
testcase_34 AC 103 ms
39,460 KB
testcase_35 AC 102 ms
39,540 KB
testcase_36 AC 103 ms
39,768 KB
testcase_37 AC 105 ms
39,768 KB
testcase_38 AC 106 ms
39,652 KB
testcase_39 AC 104 ms
39,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static boolean[][] dp;
    static boolean[][] visited;
    static int[] values;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        if (n >= 16) {
            System.out.println((1 << 16) - 1);
            return;
        }
        values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        dp = new boolean[n][1 << 16];
        visited = new boolean[n][1 << 16];
        for (int i = (1 << 16) -1; i > 0; i--) {
            if (dfw(n - 1, i)) {
                System.out.println(i);
                return;
            }
        }
    }
    
    static boolean dfw(int idx, int mask) {
        if (mask == 0) {
            return true;
        }
        if (idx < 0) {
            return false;
        }
        if (visited[idx][mask]) {
            return dp[idx][mask];
        }
        visited[idx][mask] = true;
        int value = values[idx];
        for (int i = 0; i < 16; i++) {
            dp[idx][mask] = dfw(idx - 1, mask ^ (mask & value));
            if (dp[idx][mask]) {
                return true;
            }
            value = next(value);
        }
        return dp[idx][mask];
    }
    
    static int next(int x) {
        return (x >> 1) + (1 << 15) * (x % 2);
        
    }
}
    
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0