結果

問題 No.4 おもりと天秤
ユーザー かわなかかわなか
提出日時 2016-02-06 14:17:15
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 715 bytes
コンパイル時間 465 ms
コンパイル使用メモリ 56,956 KB
実行使用メモリ 7,704 KB
最終ジャッジ日時 2023-10-21 19:27:39
合計ジャッジ時間 7,235 ms
ジャッジサーバーID
(参考情報)
judge11 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;

int n,w[100];
bool check(const int keep,int pos){
	int v = 0;
	for(int i = pos;i < n;i++){
		if(i < n){
			v = keep - w[i];
			if(v == 0){
				return true;
			} else if(v < 0){
				return false;
			} else if(check(v,i + 1)){
				return true;
			}
		}
	}
	return false; 
}

int main(void){
	int i,all = 0;
	cin >> n;
	for(i = 0;i < n;i++){
		cin >> w[i];
		all += w[i];
	}
	if(all % 2 != 0){
		cout << "impossible" << endl;
		return 0;
	}
	for(i = 0;i < n;i++){
		for(int t = i+1;t < n;t++){
			 if(w[i] > w[t]){
				int z = w[t];
				w[t] = w[i];
				w[i] = z;
			}
		}
	}
	if(check(all/2,0)){
		cout << "possible" << endl;
		return 0;	
	} 
	cout << "impossible" << endl;
}
0