結果

問題 No.2656 XOR Slimes
ユーザー parukiparuki
提出日時 2024-03-02 22:23:12
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 443 ms / 2,000 ms
コード長 867 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 6,548 KB
実行使用メモリ 43,904 KB
最終ジャッジ日時 2024-03-02 22:23:30
合計ジャッジ時間 17,735 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
37,632 KB
testcase_01 AC 66 ms
37,632 KB
testcase_02 AC 65 ms
37,632 KB
testcase_03 AC 70 ms
37,632 KB
testcase_04 AC 67 ms
37,632 KB
testcase_05 AC 68 ms
37,632 KB
testcase_06 AC 65 ms
37,632 KB
testcase_07 AC 65 ms
37,632 KB
testcase_08 AC 443 ms
43,520 KB
testcase_09 AC 282 ms
43,776 KB
testcase_10 AC 306 ms
43,776 KB
testcase_11 AC 284 ms
43,776 KB
testcase_12 AC 279 ms
43,776 KB
testcase_13 AC 282 ms
43,776 KB
testcase_14 AC 304 ms
43,776 KB
testcase_15 AC 278 ms
43,776 KB
testcase_16 AC 283 ms
43,776 KB
testcase_17 AC 281 ms
43,776 KB
testcase_18 AC 305 ms
43,776 KB
testcase_19 AC 285 ms
43,776 KB
testcase_20 AC 282 ms
43,776 KB
testcase_21 AC 281 ms
43,776 KB
testcase_22 AC 308 ms
43,760 KB
testcase_23 AC 282 ms
43,760 KB
testcase_24 AC 280 ms
43,760 KB
testcase_25 AC 279 ms
43,764 KB
testcase_26 AC 305 ms
43,760 KB
testcase_27 AC 281 ms
43,760 KB
testcase_28 AC 278 ms
43,760 KB
testcase_29 AC 279 ms
43,904 KB
testcase_30 AC 279 ms
43,904 KB
testcase_31 AC 291 ms
43,904 KB
testcase_32 AC 279 ms
43,904 KB
testcase_33 AC 280 ms
43,904 KB
testcase_34 AC 279 ms
43,904 KB
testcase_35 AC 278 ms
43,904 KB
testcase_36 AC 276 ms
43,888 KB
testcase_37 AC 277 ms
43,888 KB
testcase_38 AC 282 ms
43,888 KB
testcase_39 AC 281 ms
43,888 KB
testcase_40 AC 280 ms
43,888 KB
testcase_41 AC 279 ms
43,888 KB
testcase_42 AC 278 ms
43,888 KB
testcase_43 AC 277 ms
43,856 KB
testcase_44 AC 281 ms
43,856 KB
testcase_45 AC 282 ms
43,856 KB
testcase_46 AC 301 ms
43,848 KB
testcase_47 AC 276 ms
43,848 KB
testcase_48 AC 277 ms
43,848 KB
testcase_49 AC 278 ms
43,856 KB
testcase_50 AC 288 ms
43,680 KB
testcase_51 AC 289 ms
43,680 KB
testcase_52 AC 284 ms
43,680 KB
testcase_53 AC 283 ms
43,680 KB
testcase_54 AC 284 ms
43,680 KB
testcase_55 AC 292 ms
43,648 KB
testcase_56 AC 283 ms
43,648 KB
testcase_57 AC 286 ms
43,648 KB
testcase_58 AC 284 ms
43,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function Main(input) {
    const lines = input.split("\n");
    var n = parseInt(lines[0]);
    let xs = lines[1].split(" ").map(Number);
    let as = lines[2].split(" ").map(Number);
    let dp = Array(n+1);
    dp.fill(Infinity);
    dp[0] = 0;
    for(let i=0; i<n; ++i) {
        let sum = as[i];
        let xor = as[i];
        for(let j=i+1; ; ++j) {
            // [i, j)は一つも合体しない。
            dp[j] = Math.min(dp[j], dp[i] + sum);
            if(j==n) break;
            sum += as[j];
            xor ^= as[j];
            // iとjは合体する。このときiとj-1の間はすべて合体してよい。
            // なぜならa+b>=a xor bが成り立つから。
            dp[j+1] = Math.min(dp[j+1], dp[i] + xor + xs[j]-xs[i]);
        }
    }
    console.log(dp[n]);
}
0