結果

問題 No.1861 Required Number
ユーザー 👑 rin204rin204
提出日時 2023-04-21 23:26:04
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 280 ms / 2,500 ms
コード長 722 bytes
コンパイル時間 3,240 ms
コンパイル使用メモリ 279,412 KB
実行使用メモリ 247,544 KB
最終ジャッジ日時 2024-04-24 09:24:25
合計ジャッジ時間 10,167 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 235 ms
247,528 KB
testcase_04 AC 233 ms
247,544 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 6 ms
7,552 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 4 ms
5,504 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 5 ms
5,888 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 4 ms
5,888 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 98 ms
112,384 KB
testcase_25 AC 259 ms
232,300 KB
testcase_26 AC 130 ms
136,740 KB
testcase_27 AC 280 ms
210,560 KB
testcase_28 AC 176 ms
172,512 KB
testcase_29 AC 247 ms
225,432 KB
testcase_30 AC 260 ms
234,556 KB
testcase_31 AC 250 ms
226,176 KB
testcase_32 AC 252 ms
227,732 KB
testcase_33 AC 251 ms
226,596 KB
testcase_34 AC 247 ms
224,944 KB
testcase_35 AC 274 ms
244,224 KB
testcase_36 AC 249 ms
226,688 KB
testcase_37 AC 276 ms
243,840 KB
testcase_38 AC 248 ms
224,360 KB
testcase_39 AC 247 ms
223,616 KB
testcase_40 AC 279 ms
247,296 KB
testcase_41 AC 258 ms
233,064 KB
testcase_42 AC 280 ms
247,296 KB
testcase_43 AC 263 ms
236,672 KB
testcase_44 AC 2 ms
5,376 KB
04_evil_1.txt WA -
04_evil_2.txt WA -
04_evil_3.txt WA -
04_evil_4.txt WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n, k;
    cin >> n >> k;
    if(n > 10000 || k > 1000) return 0;
    vector<int> A(n);
    for(int i = 0; i < n; i++) cin >> A[i];
    vector<bitset<100010>> dp(n + 1);
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        dp[i + 1] = dp[i];
        dp[i + 1] |= dp[i] << A[i];
    }
    if(!dp[n][k]){
        cout << "-1\n";
        return 0;
    }
    vector<bitset<100010>> dp2(n + 1);
    dp2[n][k] = 1;
    for(int i = n - 1; i >= 0; i--){
        dp2[i] = dp2[i + 1];
        dp2[i] |= dp2[i + 1] >> A[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if((dp[i] & dp2[i + 1]).none()) ans++;
    }
    cout << ans << "\n";
}
0