結果

問題 No.4 おもりと天秤
ユーザー kekenx
提出日時 2020-01-23 11:48:09
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 619 bytes
コンパイル時間 1,283 ms
コンパイル使用メモリ 167,000 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-18 21:33:03
合計ジャッジ時間 2,441 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

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