結果

問題 No.1861 Required Number
ユーザー auauaauaua
提出日時 2022-03-04 22:09:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 2,500 ms
コード長 1,841 bytes
コンパイル時間 2,637 ms
コンパイル使用メモリ 171,824 KB
実行使用メモリ 160,440 KB
最終ジャッジ日時 2023-09-26 03:36:02
合計ジャッジ時間 10,785 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 216 ms
160,440 KB
testcase_04 AC 217 ms
160,316 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 3 ms
4,452 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 81 ms
55,796 KB
testcase_25 AC 199 ms
138,612 KB
testcase_26 AC 41 ms
25,480 KB
testcase_27 AC 85 ms
50,400 KB
testcase_28 AC 97 ms
58,592 KB
testcase_29 AC 57 ms
34,112 KB
testcase_30 AC 11 ms
9,232 KB
testcase_31 AC 198 ms
140,596 KB
testcase_32 AC 15 ms
13,616 KB
testcase_33 AC 149 ms
96,380 KB
testcase_34 AC 168 ms
114,008 KB
testcase_35 AC 174 ms
115,784 KB
testcase_36 AC 60 ms
36,004 KB
testcase_37 AC 93 ms
55,744 KB
testcase_38 AC 172 ms
118,032 KB
testcase_39 AC 111 ms
65,552 KB
testcase_40 AC 203 ms
140,040 KB
testcase_41 AC 192 ms
132,212 KB
testcase_42 AC 164 ms
107,700 KB
testcase_43 AC 96 ms
57,456 KB
testcase_44 AC 2 ms
4,376 KB
04_evil_1.txt MLE -
04_evil_2.txt MLE -
04_evil_3.txt MLE -
04_evil_4.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <unordered_set>
#include <random>
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
//#define vec vector<ll>
//#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=MOD;
const ll MAX=20000010;
const double PI=acos(-1.0);
typedef vector<vector<ll> > mat;
typedef vector<ll> vec;


void solve(){
    ll n,k;cin>>n>>k;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    vector<vector<ll> >dp(n+1,vector<ll>(k+1));
    dp[0][0]=1;
    rep(i,n){
        rep(j,k+1){
            if(dp[i][j]==0)continue;
            dp[i+1][j]=1;
            if(j+a[i]<=k)dp[i+1][j+a[i]]=1;
        }
    }
    vector<vector<ll> >dp2(n+1,vector<ll>(k+1));
    dp2[0][0]=1;
    reverse(all(a));
    rep(i,n){
        rep(j,k+1){
            if(dp2[i][j]==0)continue;
            dp2[i+1][j]=1;
            if(j+a[i]<=k)dp2[i+1][j+a[i]]=1;
        }
    }
    reverse(all(dp2));
    if(dp[n][k]==0){
        cout<<-1<<endl;
        return;
    }
    ll ans=0;
    rep(i,n){
        bool f=0;
        if(i==0){
            if(dp2[1][k]==1)f=1;
        }else if(i==n-1){
            if(dp[i][k]==1)f=1;
        }else{
            rep(j,k+1){
                if(dp[i][j]==1&&dp2[i+1][k-j]==1)f=1;
            }
        }
        //cout<<i<<' '<<f<<endl;
        if(!f)ans++;
    }
    cout<<ans<<endl;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
0