結果

問題 No.4 おもりと天秤
ユーザー kekenxkekenx
提出日時 2020-01-23 11:45:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 619 bytes
コンパイル時間 1,466 ms
コンパイル使用メモリ 163,536 KB
実行使用メモリ 4,620 KB
最終ジャッジ日時 2023-09-26 01:52:25
合計ジャッジ時間 4,052 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,424 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 2 ms
4,424 KB
testcase_04 AC 3 ms
4,396 KB
testcase_05 RE -
testcase_06 AC 2 ms
4,620 KB
testcase_07 RE -
testcase_08 AC 2 ms
4,376 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,508 KB
testcase_13 AC 2 ms
4,464 KB
testcase_14 AC 2 ms
4,392 KB
testcase_15 AC 2 ms
4,412 KB
testcase_16 AC 2 ms
4,392 KB
testcase_17 AC 2 ms
4,416 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
const int MAXW = 10005;
const int MAXN = 100;

bool dp[MAXN][MAXW];
int W[MAXN];

int main() {
  int N;
  scanf("%d", &N);
  int total = 0;
  for (int i = 0; i < N; ++i) {
    scanf("%d", &W[i]);
    total += W[i];
  }

  if (total & 1) {
    puts("impossible");
    return 0;
  }
  memset(dp, 0, sizeof(dp));
  dp[0][0] = true;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < MAXW; ++j) {
      if (dp[i][j]) {
	dp[i + 1][j + W[i]] = true;
	dp[i + 1][j] = true;
      }
    }
  }
  if (dp[N][total / 2]) puts("possible");
  else puts("impossible");
  return 0;
}
0