結果

問題 No.2656 XOR Slimes
ユーザー ks2mks2m
提出日時 2024-03-01 22:01:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 710 ms / 2,000 ms
コード長 928 bytes
コンパイル時間 2,130 ms
コンパイル使用メモリ 77,900 KB
実行使用メモリ 256,740 KB
最終ジャッジ日時 2024-03-01 22:02:22
合計ジャッジ時間 39,090 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
56,700 KB
testcase_01 AC 124 ms
57,692 KB
testcase_02 AC 116 ms
56,664 KB
testcase_03 AC 125 ms
57,564 KB
testcase_04 AC 129 ms
57,956 KB
testcase_05 AC 127 ms
57,708 KB
testcase_06 AC 127 ms
57,848 KB
testcase_07 AC 125 ms
57,960 KB
testcase_08 AC 685 ms
253,156 KB
testcase_09 AC 618 ms
253,528 KB
testcase_10 AC 659 ms
254,456 KB
testcase_11 AC 689 ms
254,452 KB
testcase_12 AC 646 ms
254,436 KB
testcase_13 AC 676 ms
254,456 KB
testcase_14 AC 678 ms
254,432 KB
testcase_15 AC 680 ms
254,492 KB
testcase_16 AC 655 ms
254,448 KB
testcase_17 AC 670 ms
254,460 KB
testcase_18 AC 699 ms
254,708 KB
testcase_19 AC 639 ms
254,452 KB
testcase_20 AC 695 ms
254,480 KB
testcase_21 AC 650 ms
254,460 KB
testcase_22 AC 688 ms
254,432 KB
testcase_23 AC 650 ms
254,448 KB
testcase_24 AC 658 ms
253,476 KB
testcase_25 AC 663 ms
254,712 KB
testcase_26 AC 682 ms
254,468 KB
testcase_27 AC 693 ms
254,448 KB
testcase_28 AC 676 ms
252,528 KB
testcase_29 AC 661 ms
253,476 KB
testcase_30 AC 650 ms
253,532 KB
testcase_31 AC 683 ms
254,432 KB
testcase_32 AC 668 ms
254,660 KB
testcase_33 AC 674 ms
254,496 KB
testcase_34 AC 698 ms
254,652 KB
testcase_35 AC 649 ms
254,452 KB
testcase_36 AC 680 ms
253,528 KB
testcase_37 AC 695 ms
256,720 KB
testcase_38 AC 651 ms
256,708 KB
testcase_39 AC 647 ms
256,720 KB
testcase_40 AC 686 ms
256,740 KB
testcase_41 AC 662 ms
256,696 KB
testcase_42 AC 657 ms
254,596 KB
testcase_43 AC 683 ms
254,588 KB
testcase_44 AC 664 ms
254,588 KB
testcase_45 AC 664 ms
254,660 KB
testcase_46 AC 648 ms
253,592 KB
testcase_47 AC 662 ms
256,708 KB
testcase_48 AC 674 ms
254,628 KB
testcase_49 AC 696 ms
254,612 KB
testcase_50 AC 624 ms
253,524 KB
testcase_51 AC 670 ms
254,652 KB
testcase_52 AC 710 ms
254,700 KB
testcase_53 AC 694 ms
254,664 KB
testcase_54 AC 702 ms
254,712 KB
testcase_55 AC 692 ms
254,708 KB
testcase_56 AC 680 ms
254,672 KB
testcase_57 AC 707 ms
254,712 KB
testcase_58 AC 670 ms
254,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] x = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
		}
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		int[] b = new int[n + 1];
		for (int i = 0; i < n; i++) {
			b[i + 1] = b[i] ^ a[i];
		}

		long[][] dp = new long[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				dp[i][j] += x[j] - x[i];
				dp[i][j] += b[j + 1] ^ b[i];
			}
		}

		long inf = 1000000000000000000L;
		long[] dp2 = new long[n + 1];
		Arrays.fill(dp2, inf);
		dp2[0] = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j < i; j++) {
				long val = dp2[j] + dp[j][i - 1];
				dp2[i] = Math.min(dp2[i], val);
			}
		}
		System.out.println(dp2[n]);
	}
}
0