結果

問題 No.1861 Required Number
ユーザー tentententen
提出日時 2022-03-07 11:15:19
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,414 bytes
コンパイル時間 4,095 ms
コンパイル使用メモリ 74,636 KB
実行使用メモリ 76,616 KB
最終ジャッジ日時 2023-09-29 10:09:53
合計ジャッジ時間 16,538 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,368 KB
testcase_01 WA -
testcase_02 AC 45 ms
49,408 KB
testcase_03 AC 269 ms
76,616 KB
testcase_04 AC 231 ms
75,524 KB
testcase_05 AC 45 ms
49,896 KB
testcase_06 AC 45 ms
49,648 KB
testcase_07 AC 47 ms
49,652 KB
testcase_08 AC 51 ms
49,436 KB
testcase_09 WA -
testcase_10 AC 47 ms
49,584 KB
testcase_11 AC 46 ms
49,240 KB
testcase_12 WA -
testcase_13 AC 48 ms
47,376 KB
testcase_14 AC 47 ms
49,408 KB
testcase_15 AC 47 ms
49,236 KB
testcase_16 WA -
testcase_17 AC 47 ms
49,468 KB
testcase_18 AC 48 ms
49,276 KB
testcase_19 AC 52 ms
50,504 KB
testcase_20 AC 49 ms
49,388 KB
testcase_21 AC 47 ms
49,352 KB
testcase_22 AC 50 ms
49,560 KB
testcase_23 AC 45 ms
49,232 KB
testcase_24 AC 117 ms
56,040 KB
testcase_25 AC 189 ms
67,856 KB
testcase_26 AC 103 ms
54,428 KB
testcase_27 AC 130 ms
56,708 KB
testcase_28 AC 134 ms
61,116 KB
testcase_29 AC 124 ms
56,996 KB
testcase_30 AC 118 ms
54,224 KB
testcase_31 AC 209 ms
75,728 KB
testcase_32 AC 131 ms
55,292 KB
testcase_33 AC 166 ms
64,660 KB
testcase_34 AC 171 ms
64,544 KB
testcase_35 AC 192 ms
65,144 KB
testcase_36 AC 139 ms
57,488 KB
testcase_37 AC 195 ms
62,236 KB
testcase_38 AC 229 ms
64,652 KB
testcase_39 AC 141 ms
61,212 KB
testcase_40 AC 252 ms
65,976 KB
testcase_41 AC 188 ms
67,824 KB
testcase_42 AC 223 ms
65,368 KB
testcase_43 AC 184 ms
63,000 KB
testcase_44 AC 46 ms
49,336 KB
04_evil_1.txt MLE -
04_evil_2.txt MLE -
04_evil_3.txt MLE -
04_evil_4.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        boolean[][] leftDP = new boolean[n][k + 1];
        leftDP[0][0] = true;
        leftDP[0][values[0]] = true;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j <= k; j++) {
                if (leftDP[i - 1][j]) {
                    leftDP[i][j] = true;
                    if (j + values[i] <= k) {
                        leftDP[i][j + values[i]] = true;
                    }
                }
            }
        }
        boolean[][] rightDP = new boolean[n][k + 1];
        rightDP[n - 1][0] = true;
        rightDP[n - 1][values[n - 1]] = true;
        for (int i = n - 2; i >= 0; i--) {
            for (int j = 0; j <= k; j++) {
                if (rightDP[i + 1][j]) {
                    rightDP[i][j] = true;
                    if (j + values[i] <= k) {
                        rightDP[i][j + values[i]] = true;
                    }
                }
            }
        }
        int ans = 0;
        for (int i = 1; i < n - 1; i++) {
            boolean enable = false;
            for (int j = 0; j <= k && !enable; j++)  {
                enable = leftDP[i - 1][j] && rightDP[i + 1][k - j];
            }
            if (!enable) {
                ans++;
            }
        }
        if (!rightDP[1][k]) {
            ans++;
        }
        if (!leftDP[n - 2][k]) {
            ans++;
        }
        System.out.println(ans);
    }
}


class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0