結果

問題 No.4 おもりと天秤
ユーザー ldsyb
提出日時 2016-03-24 16:07:30
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 390 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 54,740 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 09:27:41
合計ジャッジ時間 1,413 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

#define MAXW 10002

bool dp[MAXW];

int main(){
   dp[0] = true;
   int sum = 0,n;
   cin >> n;
   int w[n];
   for(int i = 0;i < n;i++){
      cin >> w[i];
      sum += w[i];
   }
   for(int i = 0;i < n;i++) for(int j = MAXW - 1 - w[i];j >= 0;j--) dp[j + w[i]] |= dp[j];
   cout << (sum & 1 || !dp[sum / 2] ? "impossible" : "possible") << endl;
}
0