結果

問題 No.4 おもりと天秤
ユーザー y_mazun
提出日時 2015-04-17 02:23:39
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 545 bytes
コンパイル時間 370 ms
コンパイル使用メモリ 43,136 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-26 09:10:36
合計ジャッジ時間 1,179 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int getInt()’:
main.cpp:6:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 | inline int getInt(){ int s; scanf("%d", &s); return s; }
      |                             ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <numeric>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  vector<int> w(n);
  REP(i,n) w[i] = getInt();
  const int mx = accumulate(w.begin(), w.end(), 0);

  vector<int> dp(mx + 1);
  dp[0] = 1;
  REP(i,n){
    for(int j = mx; j >= 0; j--){
      if(dp[j]) dp[j + w[i]] = 1;
    }
  }

  puts(mx % 2 == 0 && dp[mx / 2] ? "possible" : "impossible");

  return 0;
}
0