結果

問題 No.2656 XOR Slimes
ユーザー tentententen
提出日時 2024-03-04 16:59:43
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,281 bytes
コンパイル時間 2,391 ms
コンパイル使用メモリ 78,424 KB
実行使用メモリ 262,968 KB
最終ジャッジ日時 2024-03-04 16:59:51
合計ジャッジ時間 6,640 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
53,960 KB
testcase_01 AC 51 ms
53,952 KB
testcase_02 AC 51 ms
53,952 KB
testcase_03 AC 51 ms
53,980 KB
testcase_04 WA -
testcase_05 AC 52 ms
53,964 KB
testcase_06 AC 51 ms
53,996 KB
testcase_07 AC 53 ms
53,960 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
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 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static long[][] dp;
    static int[] positions;
    static int[] values;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        positions = new int[n];
        for (int i = 0; i < n; i++) {
            positions[i] = sc.nextInt();
        }
        values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        dp = new long[n][n];
        for (long[] arr : dp) {
            Arrays.fill(arr, -1);
        }
        System.out.println(dfw(0, n - 1));
    }
    
    static long dfw(int left, int right) {
        if (dp[left][right] < 0) {
            dp[left][right] = Long.MAX_VALUE;
            int current = 0;
            long distance = 0;
            for (int i = left; i < right; i++) {
                dp[left][right] = Math.min(dp[left][right], dfw(left, i) + dfw(i + 1, right));
                current ^= values[i];
                distance += Math.abs(positions[i] - positions[(left + right) / 2]);
            }
            current ^= values[right];
            distance += Math.abs(positions[right] - positions[(left + right) / 2]);
            dp[left][right] = Math.min(dp[left][right], current + distance);
        }
        return dp[left][right];
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0