結果

問題 No.4 おもりと天秤
ユーザー shimashima_k
提出日時 2015-04-28 16:01:05
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 708 bytes
コンパイル時間 1,361 ms
コンパイル使用メモリ 159,832 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-05 05:01:45
合計ジャッジ時間 2,144 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11 WA * 12
権限があれば一括ダウンロードができます

ソースコード

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 (n > x+1) return 0;
    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