結果

問題 No.4 おもりと天秤
ユーザー takatowintakatowin
提出日時 2018-02-10 23:27:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 638 bytes
コンパイル時間 493 ms
コンパイル使用メモリ 69,236 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-24 08:53:52
合計ジャッジ時間 6,977 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<map>
using namespace std;
int N,SUM=0;
int max(int a,int b){
    if(a>b)
        return a;
    else
        return b;
}
int search(int n,int s,int *w){
    if(n!=N-1)
        return max(search(n+1,s,w),search(n+1,s+w[n],w));
    else if(s==SUM/2)
        return 1;
    else
        return 0;
}
int main(){
    int i;
    cin>>N;
    int w[N];
    for(i=0;i<N;i++){
        cin>>w[i];
        SUM+=w[i];
    }
    if(SUM%2==1)
        cout<<"impossible"<<endl;
    else if(max(search(0,0,&w[0]),search(0,w[0],&w[0]))==1)
        cout<<"possible"<<endl;
    else
        cout<<"impossible"<<endl;
    return 0;
}
0