結果

問題 No.4 おもりと天秤
ユーザー pinpin
提出日時 2016-12-27 12:04:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 757 bytes
コンパイル時間 1,313 ms
コンパイル使用メモリ 51,316 KB
実行使用メモリ 7,596 KB
最終ジャッジ日時 2023-09-08 17:15:55
合計ジャッジ時間 1,922 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,336 KB
testcase_01 AC 4 ms
7,404 KB
testcase_02 AC 5 ms
7,428 KB
testcase_03 AC 4 ms
7,580 KB
testcase_04 AC 4 ms
7,368 KB
testcase_05 AC 7 ms
7,344 KB
testcase_06 AC 5 ms
7,388 KB
testcase_07 AC 7 ms
7,272 KB
testcase_08 AC 5 ms
7,344 KB
testcase_09 AC 4 ms
7,388 KB
testcase_10 AC 8 ms
7,596 KB
testcase_11 AC 5 ms
7,292 KB
testcase_12 AC 5 ms
7,340 KB
testcase_13 AC 4 ms
7,328 KB
testcase_14 AC 4 ms
7,292 KB
testcase_15 AC 4 ms
7,424 KB
testcase_16 AC 4 ms
7,276 KB
testcase_17 AC 5 ms
7,380 KB
testcase_18 AC 6 ms
7,380 KB
testcase_19 AC 7 ms
7,272 KB
testcase_20 AC 8 ms
7,336 KB
testcase_21 AC 7 ms
7,348 KB
testcase_22 AC 7 ms
7,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
using namespace std;
int dp[101][10001] ;
int N,w[100] ,sum = 0 ;
int eql(int i,int j){
     //iは添え字jはi以降の重さの総和
     if(dp[i][j]>=0) return dp[i][j] ;
     int res ;
     if(i==N){
          res = 0 ;
     }else if(j==w[i]){
          res = 1 ;
     }else{
          res = max(eql(i+1,j-w[i]),eql(i+1,j)) ;
     }
     return dp[i][j] = res ;
}


int main(void){
     
     cin >> N ;
     for(int i=0;i<N;i++){
          cin >> w[i] ;
          sum += w[i] ;
     }
     memset(dp,-1,sizeof(dp)) ;
     if(sum%2==0){
          sum /= 2 ;
          if(eql(0,sum)==1) cout << "possible" ;
          else cout << "impossible" ;
     }else{
          cout << "impossible" ;
     }
     
    
}

0