結果

問題 No.2071 Shift and OR
ユーザー tentententen
提出日時 2023-01-20 10:16:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 2,087 bytes
コンパイル時間 4,060 ms
コンパイル使用メモリ 85,276 KB
実行使用メモリ 56,948 KB
最終ジャッジ日時 2023-09-05 04:39:17
合計ジャッジ時間 9,746 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,328 KB
testcase_01 AC 44 ms
49,372 KB
testcase_02 AC 68 ms
51,600 KB
testcase_03 AC 75 ms
53,660 KB
testcase_04 AC 70 ms
51,560 KB
testcase_05 AC 97 ms
53,800 KB
testcase_06 AC 68 ms
51,696 KB
testcase_07 AC 69 ms
51,476 KB
testcase_08 AC 66 ms
51,624 KB
testcase_09 AC 72 ms
51,704 KB
testcase_10 AC 68 ms
51,572 KB
testcase_11 AC 107 ms
53,820 KB
testcase_12 AC 118 ms
53,720 KB
testcase_13 AC 102 ms
53,744 KB
testcase_14 AC 45 ms
49,396 KB
testcase_15 AC 88 ms
53,984 KB
testcase_16 AC 85 ms
53,940 KB
testcase_17 AC 105 ms
53,876 KB
testcase_18 AC 46 ms
49,492 KB
testcase_19 AC 119 ms
54,392 KB
testcase_20 AC 112 ms
53,996 KB
testcase_21 AC 147 ms
54,556 KB
testcase_22 AC 133 ms
54,268 KB
testcase_23 AC 141 ms
56,744 KB
testcase_24 AC 84 ms
55,656 KB
testcase_25 AC 96 ms
56,532 KB
testcase_26 AC 113 ms
54,912 KB
testcase_27 AC 71 ms
55,748 KB
testcase_28 AC 147 ms
56,560 KB
testcase_29 AC 147 ms
56,948 KB
testcase_30 AC 81 ms
53,804 KB
testcase_31 AC 69 ms
53,616 KB
testcase_32 AC 73 ms
54,020 KB
testcase_33 AC 73 ms
53,836 KB
testcase_34 AC 68 ms
53,792 KB
testcase_35 AC 72 ms
54,288 KB
testcase_36 AC 75 ms
53,744 KB
testcase_37 AC 75 ms
53,708 KB
testcase_38 AC 73 ms
53,992 KB
testcase_39 AC 72 ms
53,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static int[] values;
    static int[][] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = Math.min(sc.nextInt(), 16);
        values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        dp = new int[n][1 << 16];
        System.out.println(dfw(n - 1, 0));
    }
    
    static int dfw(int idx, int x) {
        if (idx < 0) {
            return x;
        }
        if (dp[idx][x] == 0) {
            for (int i = 0; i < 16; i++) {
                dp[idx][x] = Math.max(dp[idx][x], dfw(idx - 1, x | values[idx]));
                values[idx] = (values[idx] >> 1) | ((values[idx] % 2) << 15);
            }
        }
        return dp[idx][x];
    }
}

class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0