結果

問題 No.4 おもりと天秤
ユーザー Gredt8Gredt8
提出日時 2019-08-14 14:35:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 2,490 bytes
コンパイル時間 849 ms
コンパイル使用メモリ 91,560 KB
実行使用メモリ 4,680 KB
最終ジャッジ日時 2023-10-19 18:07:20
合計ジャッジ時間 1,829 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << n); bit++)
using namespace std;

template<class T>
void print(const T &value) {
    std::cout << value << std::endl;
}

void yesno(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; }

void YesNo(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll INF = 10000000;
ll mod = 1000000007;//10^9+7
int dx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int dy[8] = {0, -1, 1, 0, -1, 1, -1, 1};
using Graph = vector<vector<int>>;//隣接リスト:G[i]にはiと隣接する頂点が入るよ。
using P = pair<int, int>;//BFSで利用。queueに入れる。
using PP = pair<int, P>; //dijkstraで利用,priority_queueに入れる。
using p_queue = priority_queue<int, vector<int>, greater<int>()>;
//struct edge{int to, cost};

void factorization(int N, map<int, int> &Prime) {
    int a = 2;
    while (a * a <= N) {
        if (N % a == 0) {
            N /= a;
            if (Prime.count(a)) { Prime[a] += 1; }
            else { Prime[a] = 1; }
        } else {
            a++;
        }
    }
    if (N != 1) {
        Prime[N] = 1;
    }
}


//番号ズレ注意!!
int main() {
    int N;
    cin >> N;
    int W[N];
    int sum = 0;
    REP(i, N) {
        cin >> W[i];
        sum += W[i];
    }
    if (sum % 2 == 1) {
        cout << "impossible" << endl;
        return 0;
    }
    bool dp[N + 1][10001];
    REP(i, N + 1) { REP(j, 10001) { dp[i][j] = false; }}
    dp[0][0] = true;
    REP(i, N) {
        REP(j, 10001) {
            if (dp[i][j]) {
                dp[i + 1][j + W[i]] = true;
                dp[i + 1][j] = true;
            }
        }
    }
    if (dp[N][sum / 2]) { print("possible"); }
    else { print("impossible"); }

}

0