結果

問題 No.4 おもりと天秤
ユーザー chakkuchakku
提出日時 2015-09-14 21:37:06
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 740 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 61,108 KB
実行使用メモリ 7,576 KB
最終ジャッジ日時 2023-09-26 11:54:32
合計ジャッジ時間 7,621 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

int p;
int w[101];
int ww[101];
int n;

bool dfs(int cur,int weight){
    if(weight==p) return true;
    if(cur==n) return false;
    if(weight>p) return false;
    if(dfs(cur+1,weight+w[cur])) return true;
    if(dfs(cur+1,weight)) return true;
    return false;
}

int main(){
    cin>>n;
    for(int i=0;i<n;i++) cin >> ww[i];
    int sum=0;
    for(int i=0;i<n;i++) sum+=ww[i];
    if(sum%2){
        cout << "impossible" << endl;
        return 0;
    }
    sort(ww,ww+n);
    for(int i=n-1;i>=0;i--){
        w[i] = ww[n-i-1];
    }
    p=sum/2;
    if(dfs(0,0)){
        cout << "possible" << endl;
    }else{
        cout << "impossible" << endl;
    }
    return 0;
}
0