結果

問題 No.4 おもりと天秤
ユーザー dgd1724dgd1724
提出日時 2016-10-04 19:53:23
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,997 bytes
コンパイル時間 1,081 ms
コンパイル使用メモリ 105,232 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-05-01 12:16:48
合計ジャッジ時間 7,515 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>			//std::cout, std::cin
#include <string>			//std::string,std::to_string(C++11)
#include <vector>			//std::vector
#include <valarray>			//std::valarray
#include <algorithm>		//std::sort
#include <ctime>			//localtime_s
#include <cstdlib>			//abs
#include <cmath>			//abs,std::pow,sqrt,sin,cos,round,floor,ceil
#include <fstream>			//std::ifstream,std::ofstream
#include <iomanip>			//std::setprecision,std::setw,std::setfill
#include <random>			//std::random(C++11)
#include <numeric>			//std::accumulate
#include <functional>		//std::greater
#include <chrono>			//std::chrono(C++11)
#include <bitset>			//std::bitset
#include <queue>			//std::queue

const static double			de_PI = 3.14159265358979323846;
const static unsigned int	de_MOD = 1000000007;
const static int			de_MAX = 999999999;

void Calc(bool *flg, const int digit, const int compare, std::vector<int> &W, int total, const int st) {

	for (unsigned int i = 0; !*flg && i < W.size(); i++) {
		total += W[i];
		if (total > compare) {
			break;
		}
		if (digit > 1) {
			Calc(flg, digit - 1, compare, W, total, st + 1);
		}
		if (total == compare) {
			*flg = true;
		}
	}

}

int main(void) {

	//std::ifstream in("123.txt");	std::cin.rdbuf(in.rdbuf());
	//std::ofstream ofs("456.csv");
	//std::chrono::system_clock::time_point t_st = std::chrono::system_clock::now();

	int N = 0, sum = 0;
	std::cin >> N;
	std::vector<int> W(N);
	for (int i = 0; i < N; i++) {
		std::cin >> W[i];
		sum += W[i];
	}

	if (sum % 2 == 1) {
		std::cout << "impossible" << std::endl;
		return 0;
	}

	std::sort(W.begin(), W.end());
	bool flg = false;
	for (int i = 1; i <= N / 2; i++) {
		Calc(&flg, i, sum / 2, W, 0, 0);
	}

	if (flg) {
		std::cout << "possible" << std::endl;
	}
	else {
		std::cout << "impossible" << std::endl;
	}


	//std::chrono::system_clock::time_point t_ed = std::chrono::system_clock::now();
	//std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t_ed - t_st).count() << "ms" << std::endl;

}

0