結果

問題 No.4 おもりと天秤
ユーザー imulanimulan
提出日時 2015-12-16 12:30:19
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 757 bytes
コンパイル時間 473 ms
コンパイル使用メモリ 63,216 KB
実行使用メモリ 9,824 KB
最終ジャッジ日時 2023-10-14 10:46:16
合計ジャッジ時間 7,335 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

int n;
const int N=100;
vector<int> w(N);
int sum=0;

int dp[101][5001];
//x番目に注目していて、現在の重さはy
int rec(int x, int y){
  if(x==n) return (y==sum/2);
  if(dp[x][y]>=0) return dp[x][y];

  int ret;
  if(y+w[x]>sum/2) ret = rec(x+1,y);
  else ret = rec(x+1,y) || rec(x+1, y+w[x]);
  return ret;
}

int main(int argc, char const *argv[]) {
  cin >>n;
  for(int i=0; i<n; ++i){
    scanf(" %d", &w[i]);
    sum += w[i];
  }

  memset(dp, -1, sizeof(dp));

  if(sum%2==0){
    int ret=rec(0, 0);
    if(ret==1) printf("possible\n");
    else printf("impposible\n");
  }
  else printf("impposible\n");
  return 0;
}
0