結果
| 問題 | 
                            No.4 おもりと天秤
                             | 
                    
| コンテスト | |
| ユーザー | 
                             shimashima_k
                         | 
                    
| 提出日時 | 2015-04-28 15:57:31 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 670 bytes | 
| コンパイル時間 | 1,348 ms | 
| コンパイル使用メモリ | 162,040 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-07-05 05:01:32 | 
| 合計ジャッジ時間 | 2,218 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 WA * 13 | 
ソースコード
#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) 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;
}
            
            
            
        
            
shimashima_k