結果

問題 No.4 おもりと天秤
ユーザー kekenxkekenx
提出日時 2020-01-23 11:48:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 619 bytes
コンパイル時間 1,513 ms
コンパイル使用メモリ 163,364 KB
実行使用メモリ 4,660 KB
最終ジャッジ日時 2023-09-26 02:10:44
合計ジャッジ時間 2,688 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,432 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 3 ms
4,520 KB
testcase_03 AC 2 ms
4,428 KB
testcase_04 AC 3 ms
4,384 KB
testcase_05 AC 4 ms
4,660 KB
testcase_06 AC 3 ms
4,448 KB
testcase_07 AC 4 ms
4,504 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 4 ms
4,528 KB
testcase_10 AC 4 ms
4,452 KB
testcase_11 AC 3 ms
4,660 KB
testcase_12 AC 2 ms
4,472 KB
testcase_13 AC 2 ms
4,452 KB
testcase_14 AC 2 ms
4,532 KB
testcase_15 AC 2 ms
4,428 KB
testcase_16 AC 3 ms
4,608 KB
testcase_17 AC 2 ms
4,656 KB
testcase_18 AC 4 ms
4,516 KB
testcase_19 AC 4 ms
4,504 KB
testcase_20 AC 4 ms
4,580 KB
testcase_21 AC 4 ms
4,452 KB
testcase_22 AC 4 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
const int MAXW = 10105;
const int MAXN = 105;

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