結果

問題 No.4 おもりと天秤
ユーザー ei1333333ei1333333
提出日時 2014-10-29 22:25:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 557 bytes
コンパイル時間 1,231 ms
コンパイル使用メモリ 144,236 KB
実行使用メモリ 5,596 KB
最終ジャッジ日時 2023-09-08 16:02:21
合計ジャッジ時間 2,348 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,484 KB
testcase_01 AC 3 ms
5,596 KB
testcase_02 AC 4 ms
5,436 KB
testcase_03 AC 3 ms
5,432 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 6 ms
5,372 KB
testcase_06 AC 3 ms
5,380 KB
testcase_07 AC 6 ms
5,380 KB
testcase_08 AC 6 ms
5,380 KB
testcase_09 AC 6 ms
5,432 KB
testcase_10 AC 6 ms
5,312 KB
testcase_11 AC 3 ms
5,300 KB
testcase_12 AC 3 ms
5,372 KB
testcase_13 AC 3 ms
5,308 KB
testcase_14 AC 3 ms
5,312 KB
testcase_15 AC 3 ms
5,300 KB
testcase_16 AC 3 ms
5,312 KB
testcase_17 AC 3 ms
5,592 KB
testcase_18 AC 6 ms
5,312 KB
testcase_19 AC 6 ms
5,308 KB
testcase_20 AC 6 ms
5,300 KB
testcase_21 AC 6 ms
5,300 KB
testcase_22 AC 6 ms
5,304 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
const int INF = 1 << 30;

int main(){
  int N, W[100];
  bool dp[101][20002] = {};
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> W[i];
  }
  dp[0][10001] = true;
  for(int i = 0; i < N; i++){
    for(int j = W[i]; j <= 20001; j++){
      dp[i + 1][j - W[i]] |= dp[i][j];
    }
    for(int j = 20001 - W[i]; j >= 0; j--){
      dp[i + 1][j + W[i]] |= dp[i][j];
    }
  }
  if(dp[N][10001]) cout << "possible" << endl;
  else cout << "impossible" << endl;
}
0