結果

問題 No.1861 Required Number
ユーザー milanis48663220milanis48663220
提出日時 2022-03-04 21:33:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 46 ms / 2,500 ms
コード長 2,237 bytes
コンパイル時間 1,211 ms
コンパイル使用メモリ 119,108 KB
実行使用メモリ 23,104 KB
最終ジャッジ日時 2023-09-26 03:13:26
合計ジャッジ時間 10,337 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,420 KB
testcase_01 AC 3 ms
5,488 KB
testcase_02 AC 2 ms
5,464 KB
testcase_03 AC 45 ms
23,104 KB
testcase_04 AC 46 ms
23,004 KB
testcase_05 AC 2 ms
5,404 KB
testcase_06 AC 2 ms
5,420 KB
testcase_07 AC 2 ms
5,424 KB
testcase_08 AC 3 ms
5,708 KB
testcase_09 AC 2 ms
5,404 KB
testcase_10 AC 2 ms
5,456 KB
testcase_11 AC 2 ms
5,420 KB
testcase_12 AC 2 ms
5,456 KB
testcase_13 AC 2 ms
5,540 KB
testcase_14 AC 2 ms
5,696 KB
testcase_15 AC 2 ms
5,544 KB
testcase_16 AC 2 ms
5,436 KB
testcase_17 AC 2 ms
5,568 KB
testcase_18 AC 3 ms
5,544 KB
testcase_19 AC 3 ms
5,512 KB
testcase_20 AC 3 ms
5,508 KB
testcase_21 AC 3 ms
5,472 KB
testcase_22 AC 2 ms
5,508 KB
testcase_23 AC 2 ms
5,424 KB
testcase_24 AC 19 ms
15,788 KB
testcase_25 AC 41 ms
22,656 KB
testcase_26 AC 12 ms
17,708 KB
testcase_27 AC 20 ms
21,872 KB
testcase_28 AC 21 ms
21,996 KB
testcase_29 AC 16 ms
22,068 KB
testcase_30 AC 10 ms
22,448 KB
testcase_31 AC 42 ms
22,288 KB
testcase_32 AC 10 ms
22,144 KB
testcase_33 AC 31 ms
22,172 KB
testcase_34 AC 35 ms
22,352 KB
testcase_35 AC 37 ms
22,824 KB
testcase_36 AC 17 ms
22,196 KB
testcase_37 AC 22 ms
23,012 KB
testcase_38 AC 36 ms
22,008 KB
testcase_39 AC 23 ms
22,072 KB
testcase_40 AC 42 ms
22,948 KB
testcase_41 AC 39 ms
22,588 KB
testcase_42 AC 35 ms
22,952 KB
testcase_43 AC 22 ms
22,600 KB
testcase_44 AC 2 ms
5,404 KB
04_evil_1.txt RE -
04_evil_2.txt RE -
04_evil_3.txt RE -
04_evil_4.txt RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

bool dpl[10001][1001];
bool dpr[10001][1001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    dpl[0][0] = true;
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= k; j++){
            if(dpl[i][j]){
                dpl[i+1][j] = true;
                if(j+a[i] <= k) dpl[i+1][j+a[i]] = true;
            }
        }
    }
    dpr[n][0] = true;
    for(int i = n-1; i >= 0; i--){
        for(int j = 0; j <= k; j++){
            if(dpr[i+1][j]){
                dpr[i][j] = true;
                if(j+a[i] <= k) dpr[i][j+a[i]] = true;
            }
        }
    }
    if(!dpl[n][k]){
        cout << -1 << endl;
        return 0;
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        bool ok = false;
        for(int j = 0; j <= k; j++){
            if(dpl[i][j] && dpr[i+1][k-j]) {
                ok = true;
            }
        }
        if(!ok) ans++;
    }
    cout << ans << endl;
}
0