結果

問題 No.4 おもりと天秤
ユーザー shimashima_kshimashima_k
提出日時 2015-04-28 15:59:46
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 676 bytes
コンパイル時間 1,210 ms
コンパイル使用メモリ 146,200 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-18 14:04:30
合計ジャッジ時間 4,469 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

int sum;
int x;
vector<int> w;

int solve(int n, int total) {
    if (total==sum) return 1;
    else if (total > sum) return 0;
    else if (solve(n+1, total + w[n])==1) return 1;
    else if (solve(n+1, total) == 1) return 1;
    else return 0;
}

int main() {
    int x;
    sum = 0;
    cin>>x;
    for(int i=0; i<x;i++) {
        int a;
        cin >> a;
        sum += a;
        w.push_back(a);
    }
    if (sum%2==1){
        cout<<"impossible"<<endl;
        return 0;
    }

    sum /= 2;
    if (solve(0,0) == 1) {
        cout<<"possible"<<endl;
    } else {
        cout<<"impossible"<<endl;
    }

    return 0;
}

0