結果

問題 No.137 貯金箱の焦り
ユーザー yaoshimaxyaoshimax
提出日時 2015-04-30 16:56:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 282 ms / 5,000 ms
コード長 1,099 bytes
コンパイル時間 867 ms
コンパイル使用メモリ 86,040 KB
実行使用メモリ 22,656 KB
最終ジャッジ日時 2024-04-25 11:52:35
合計ジャッジ時間 2,824 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 5 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 282 ms
22,656 KB
testcase_13 AC 29 ms
14,464 KB
testcase_14 AC 140 ms
13,440 KB
testcase_15 AC 124 ms
12,032 KB
testcase_16 AC 121 ms
11,520 KB
testcase_17 AC 38 ms
6,144 KB
testcase_18 AC 106 ms
11,008 KB
testcase_19 AC 131 ms
12,928 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 61 ms
7,680 KB
testcase_22 AC 9 ms
5,376 KB
testcase_23 AC 8 ms
5,376 KB
testcase_24 AC 29 ms
5,760 KB
testcase_25 AC 81 ms
9,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <queue>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>

using namespace std;

long long dp[51][50002];
int main(){
   long long N,M;
   cin >> N >> M;
   int A[N];
   int sum=0;
   for( int i = 0 ; i <N ; i++ ) cin>>A[i],sum+=A[i];
   dp[0][0]=1;
   int mod=1234567891;
   while(M>0){
      for( int i = 0 ; i <N ; i++ ){
       for( int j = 2*sum; j>=0;j--){
         dp[i+1][j]=dp[i][j];
         if( j-A[i] >=0){
            dp[i+1][j]+=dp[i][j-A[i]];
            dp[i+1][j]%=mod;
         }
       }
      }
      for( int i=0; i<=sum; i++ ){
         //if( i*2+M%2 <= M) cout << i*2+M%2 << "="<<dp[N][i*2+M%2]<<endl;
         dp[0][i]=dp[N][i*2+M%2];
      }
      for( int i=sum+1; i< 2*sum+2; i++ ){
         dp[0][i]=0;
      }
      M/=2;
   }
   cout << dp[0][0];
   return 0;
}
0