結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  bleuloverblue | 
| 提出日時 | 2020-09-29 13:40:38 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,121 bytes | 
| コンパイル時間 | 1,573 ms | 
| コンパイル使用メモリ | 174,720 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-03 20:02:17 | 
| 合計ジャッジ時間 | 2,519 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 12 WA * 11 | 
ソースコード
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using usize = ::std::size_t;
//using u64 = ::std::int_least64_t;
using u64 = long long;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int main(int argc, char *argv[])
{
    std::ifstream in("in.txt");
    std::cin.rdbuf(in.rdbuf());
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    vector<int> W(N), Ws(N,0);
    for (int i = 0; i < N; i++) {
        cin >> W[i];
        if(i) Ws[i] += Ws[i - 1] + W[i];
        else Ws[i] += W[i];
    }
    vector<vector<bool>> dp(N+1,vector<bool>(Ws[N-1]+1,false));
    dp[0][0] = true;
    for (int i = 0; i < N; i++) {
        for (int k = 0; k <= Ws[i]; k++) {
            dp[i+1][k] = dp[i][abs(k - W[i])];
        }
    }
    
    if(dp[N][0]) cout << "possible" << endl;
    else cout << "impossible" << endl;
    
    return 0;
    
}
            
            
            
        