結果

問題 No.4 おもりと天秤
ユーザー hokutohokuto
提出日時 2021-08-30 22:02:52
言語 C++17(clang)
(14.0.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 826 bytes
コンパイル時間 1,477 ms
コンパイル使用メモリ 104,704 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-15 21:27:43
合計ジャッジ時間 2,761 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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));


int main(int argc, char const *argv[])
{
  vector<vector<int>> dp(101,vector<int>(1001,0));
  int N; cin >> N;
  vector<int> W(N);
  for(auto &e :W)cin >> e;
  dp[0][0] = 1;
  for(int i=0;i<N;++i)
  {
    for(int j=0;j<=1000;++j)
    {
      if(dp[i][j])
      {
        if(j+W[i] <= 1000)dp[i+1][j+W[i]] = 1;
        if(j - W[i] >= 0)dp[i+1][j-W[i]] = 1;
      }
    }
  }
  if(dp[N][0])std::cout << "possible" << std::endl;
  else std::cout << "impossible" << std::endl;
}
0