結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-08-30 22:06:05 | 
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 5,000 ms | 
| コード長 | 814 bytes | 
| コンパイル時間 | 1,524 ms | 
| コンパイル使用メモリ | 142,424 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-24 06:16:49 | 
| 合計ジャッジ時間 | 2,340 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#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;
        dp[i+1][abs(j-W[i])] = 1;
      }
    }
  }
  if(dp[N][0])std::cout << "possible" << std::endl;
  else std::cout << "impossible" << std::endl;
}
            
            
            
        