結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-07-08 13:20:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,026 bytes |
| コンパイル時間 | 485 ms |
| コンパイル使用メモリ | 53,984 KB |
| 実行使用メモリ | 8,576 KB |
| 最終ジャッジ日時 | 2024-07-08 01:42:13 |
| 合計ジャッジ時間 | 7,007 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 TLE * 1 -- * 17 |
ソースコード
//
// 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(nowWeight > sum - nowWeight || 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;
}