結果
問題 |
No.1861 Required Number
|
ユーザー |
|
提出日時 | 2021-12-27 02:51:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 843 bytes |
コンパイル時間 | 2,058 ms |
コンパイル使用メモリ | 200,796 KB |
最終ジャッジ日時 | 2025-01-27 07:17:13 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 6 WA * 36 MLE * 4 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ int N,K; cin>>N>>K; vector<int>A(N); for(int i=0;i<N;i++)cin>>A[i]; vector<vector<bool>>dpl(N+1,vector<bool>(K+1,false)),dpr(N+2,vector<bool>(K+1,false)); dpl[0][0]=dpr[N+1][0]=true; for(int i=0;i<N;i++){ for(int j=0;j<=K-A[i];j++){ if(dpl[i][j])dpl[i+1][j+A[i]]=true; } } for(int i=N-1;i>=0;i--){ for(int j=0;j<=K-A[i];j++){ if(dpr[i+2][j])dpr[i+1][j+A[i]]=true; } } if(!dpl[N][K]){ cout<<-1<<endl; return 0; } int ans=0; for(int i=1;i<=N;i++){ bool flag=true; for(int j=0;j<=K;j++){ if(dpl[i-1][j]&&dpr[i+1][K-j])flag=false; } if(flag)ans++; } cout<<ans<<endl; }