結果

問題 No.4 おもりと天秤
ユーザー 4885rhkA
提出日時 2015-07-08 13:18:20
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 995 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 55,028 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-07-08 01:41:48
合計ジャッジ時間 7,029 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

//
//  main.cpp
//  Q19
//
//  Created by AkihiroKOBAYASHI on 7/6/15.
//  Copyright (c) 2015 Akhr5884. All rights reserved.
//

#include <iostream>

int *w;
int sum;
int n;
int check;

void judge(int nowWeight, int nowNumber) {
    if(nowWeight == sum-nowWeight) {
        check = 1;
        return;
    }
    else if(nowNumber == n) {
        return;
    }
    else {
        // add
        judge(nowWeight, nowNumber + 1);
        
        // not add
        judge(nowWeight + w[nowNumber], nowNumber + 1);
    }
    return;
    
}

int main(int argc, const char * argv[]) {
    
    
    std::cin >> n;
    w = (int*)malloc(sizeof(w) * n);
    
    int count = 0;
    sum = 0;
    while (count < n) {
        int wi;
        std::cin >> wi;
        w[count] = wi;
        sum += wi;
        count++;
    }
    
    check = 0;
    judge(0, 0);
    
    if(check == 1) {
        std::cout << "possible" << "\n";
    }
    else {
        std::cout << "impossible" << "\n";
    }

    return 0;
}
0