結果

問題 No.4 おもりと天秤
ユーザー あっちむいてホイ!あっちむいてホイ!
提出日時 2021-10-30 00:51:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,101 bytes
コンパイル時間 980 ms
コンパイル使用メモリ 97,704 KB
実行使用メモリ 7,680 KB
最終ジャッジ日時 2024-04-16 16:05:21
合計ジャッジ時間 4,766 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <utility>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
using namespace std;
using ll = long long int;
#define chmax(x,y)  (x) = ((x) > (y)) ? (x) : ((x) = (y));
#define chmin(x,y)  (x) = ((x) < (y)) ? (x) : ((x) = (y));
const int INF = 1e9;
const ll INFL = 1e18;
const int Mod = 1e9 + 7;
const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};


int main(int argc, char const *argv[])
{
  int N; cin >> N;
  vector<int> W(N);for(auto &w : W)cin >> w;
  vector<vector<int>> dp(1001,vector<int>(1001));
  dp[0][0] = 1;
  for(int i=0;i<N;++i)
  {
    for(int i=0;i<1000;++i)
    {
      for(int j=0;j<1000;++j)
      {
        if(i+W[i] > 1000)continue;
        dp[i+W[i]][j] = dp[i][j];
        if(j + W[i] > 1000)continue;
        dp[i][j+W[i]] = dp[i][j];
      }
    }
  }

  for(int i=1;i<1000;++i)
  {
    if(dp[i][i])
    {
      std::cout << "possible" << std::endl;
      return 0;
    }
  }
  std::cout << "impossible" << std::endl;
  return 0;
}
0