結果

問題 No.4 おもりと天秤
ユーザー bleuloverbluebleuloverblue
提出日時 2020-09-29 13:40:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,121 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 172,468 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-16 20:55:52
合計ジャッジ時間 2,579 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
    
}
0