結果

問題 No.4 おもりと天秤
ユーザー Asdf_QwertyZAsdf_QwertyZ
提出日時 2018-06-05 23:14:17
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 518 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 32,264 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 22:37:09
合計ジャッジ時間 1,184 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

constexpr int MAX_N = 100;

int N;
int W[MAX_N], S;
bool dp[10001];

int main()
{
  scanf( "%d", &N );
  rep( i, N )
    scanf( "%d", W+i ), S += W[i];

  if( S % 2 == 1 )
  {
    puts("impossible");

    return 0;
  }

  dp[0] = true;
  rep( i, N ) for( int j = S; j >= 0; --j ) if( j-W[i] >= 0 )
    dp[j] |= dp[j-W[i]];

  puts( dp[S/2] ? "possible" : "impossible" );
  
  return 0;
}
0