結果

問題 No.973 余興
ユーザー tentententen
提出日時 2023-06-08 17:38:03
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,573 bytes
コンパイル時間 3,914 ms
コンパイル使用メモリ 79,752 KB
実行使用メモリ 117,380 KB
最終ジャッジ日時 2023-08-29 22:53:49
合計ジャッジ時間 17,615 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 525 ms
117,380 KB
testcase_01 AC 576 ms
95,752 KB
testcase_02 AC 524 ms
96,756 KB
testcase_03 AC 497 ms
96,592 KB
testcase_04 AC 527 ms
95,948 KB
testcase_05 AC 531 ms
95,816 KB
testcase_06 AC 596 ms
96,372 KB
testcase_07 AC 523 ms
95,784 KB
testcase_08 AC 532 ms
96,704 KB
testcase_09 AC 508 ms
96,300 KB
testcase_10 AC 556 ms
96,064 KB
testcase_11 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static long[] sums;
    static boolean[][] wins;
    static boolean[][] used;
    static int x;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        x = sc.nextInt();
        sums = new long[n + 1];
        for (int i = 1; i <= n; i++) {
            sums[i] = sums[i - 1] + sc.nextInt();
        }
        wins = new boolean[n + 1][n + 1];
        used = new boolean[n + 1][n + 1];
        if (dfw(0, n)) {
            System.out.println("A");
        } else {
            System.out.println("B");
        }
    }
    
    static boolean dfw(int left, int right) {
        if (right - left == 1) {
            return false;
        }
        if (sums[right] - sums[left] <= x) {
            return true;
        }
        if (!used[left][right]) {
            used[left][right] = true;
            for (int i = left + 1; i < right && sums[i] - sums[left] <= x && !wins[left][right]; i++) {
                wins[left][right] = !dfw(i, right);
            }
            for (int i = right - 1; i > left && sums[right] - sums[i] <= x && !wins[left][right]; i--) {
                wins[left][right] = !dfw(left, i);
            }
        }
        return wins[left][right];
    }
}
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