結果

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

テストケース

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

ソースコード

diff #

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

int main(int argc, char const *argv[]) {
  int n;
  int sum=0;

  cin >>n;
  vector<int> w(n);

  for(int i=0; i<n; ++i){
    scanf(" %d", &w[i]);
    sum += w[i];
  }


  if(sum%2==0){
    //x番目までで重さyをつくれるか
    bool dp[101][5010];

    for(int i=0; i<n; ++i)
    for(int j=0; j<=sum/2; ++j)
    dp[i][j]=false;

    //初期化
    for(int i=0; i<n; ++i) dp[i][0]=true;
    dp[0][w[0]] =true;
    for(int i=1; i<n; ++i){
      for(int j=0; j<=sum/2; ++j) dp[i][j]=dp[i-1][j];

      for(int j=0; j<=sum/2; ++j){
        if(dp[i-1][j] && j+w[i]<=sum/2) dp[i][j+w[i]] = true;
      }
    }

    /*
    for(int i=0; i<n; ++i){
      for(int j=0; j<=sum/2; ++j) printf(" %d", dp[i][j]);
      printf("\n");
    }
    */
    if(dp[n-1][sum/2]) printf("possible\n");
    else printf("impposible\n");
  }
  else printf("impposible\n");
  return 0;
}
0