結果

問題 No.1246 ANDORゲーム(max)
ユーザー tentententen
提出日時 2020-10-05 09:21:58
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,274 bytes
コンパイル時間 4,846 ms
コンパイル使用メモリ 75,524 KB
実行使用メモリ 385,264 KB
最終ジャッジ日時 2023-09-27 01:46:49
合計ジャッジ時間 13,720 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,080 KB
testcase_01 AC 126 ms
55,588 KB
testcase_02 AC 126 ms
55,504 KB
testcase_03 AC 125 ms
56,088 KB
testcase_04 AC 124 ms
55,640 KB
testcase_05 AC 133 ms
55,452 KB
testcase_06 AC 131 ms
55,560 KB
testcase_07 AC 129 ms
55,444 KB
testcase_08 AC 133 ms
55,284 KB
testcase_09 AC 130 ms
55,544 KB
testcase_10 AC 125 ms
55,324 KB
testcase_11 AC 342 ms
64,224 KB
testcase_12 AC 223 ms
58,424 KB
testcase_13 AC 256 ms
58,280 KB
testcase_14 AC 401 ms
67,280 KB
testcase_15 AC 394 ms
67,200 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        ArrayList<HashMap<Integer, Long>> dp = new ArrayList<>();
        for (int i = 0; i <= n; i++) {
            dp.add(new HashMap<>());
        }
        dp.get(0).put(t, 0L);
        for (int i = 1; i <= n; i++) {
            int a = sc.nextInt();
            for (Map.Entry<Integer, Long> entry : dp.get(i - 1).entrySet()) {
                int next1 = (entry.getKey() & a);
                long value1 = entry.getValue() + Math.abs(next1 - entry.getKey());
                if (!dp.get(i).containsKey(next1) || dp.get(i).get(next1) < value1) {
                    dp.get(i).put(next1, value1);
                }
                int next2 = (entry.getKey() | a);
                long value2 = entry.getValue() + Math.abs(next2 - entry.getKey());
                if (!dp.get(i).containsKey(next2) || dp.get(i).get(next2) < value2) {
                    dp.get(i).put(next2, value2);
                }
            }
        }
        long max = 0;
        for (long x : dp.get(n).values()) {
            max = Math.max(max, x);
        }
        System.out.println(max);
    }
}
0