結果

問題 No.4 おもりと天秤
ユーザー amesyuamesyu
提出日時 2019-11-16 13:52:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,408 bytes
コンパイル時間 1,128 ms
コンパイル使用メモリ 58,720 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 03:51:07
合計ジャッジ時間 1,525 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//#include <bits/stdc++.h>
//#include "includes.h"
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
#define INF 10000000000000
int main() {
    long long b, c, n, m;
    long long k1, k2;
    long long s = 0;
    cin >> n;
    long long w[n];
    for(int i=0;i<n;i++) {
        cin >> b;
        s += b;
        w[i] = b;
    }
    if(s%2 != 0) {
        cout << "impossible" << endl;
        return 0;
    } else {
        m = b/2;
    }
    //cout << "A" << endl;
    int dp[n+1][m+1];
    for(int i=0;i<m+1;i++) {
        dp[0][i] = 0;
    }
    //cout << "B" << endl;
    //cout << "C" << endl;
    for(int i=0;i<n;i++) {
        for(int j=0;j<m+1;j++) {
            if (j >= w[i]) {
                k1 = dp[i][j];
                k2 = dp[i][j-w[i]] + 1;
                if(k1 == m || k2 == m) {
                    cout << "possible" << endl;
                    return 0;
                }
                dp[i+1][j] = max(k1, k2);
            } else {
                if (dp[i][j] == m) {
                    cout << "possible" << endl;
                    return 0;
                }
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    //cout << "D" << endl;
    //for(int i=0;i<n+1;i++) {
    //    for(int j=0;j<m+1;j++) {
    //        cout << dp[i][j] << " ";
    //    }
    //    cout << endl;
    //}
    cout << "impossible" << endl;
}
0