結果

問題 No.4 おもりと天秤
ユーザー kkslucy1kkslucy1
提出日時 2018-03-08 22:11:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 699 bytes
コンパイル時間 3,942 ms
コンパイル使用メモリ 150,184 KB
実行使用メモリ 8,148 KB
最終ジャッジ日時 2023-09-08 17:43:14
合計ジャッジ時間 3,034 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 3 ms
4,508 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 8 ms
4,876 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 9 ms
5,120 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 8 ms
4,664 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 23 ms
8,148 KB
testcase_19 AC 9 ms
5,432 KB
testcase_20 AC 7 ms
5,060 KB
testcase_21 AC 7 ms
4,832 KB
testcase_22 AC 8 ms
5,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
	int n, half;
	int w[101];
	cin >> n;
	half = 0;
	for (int i = 1;i <= 100;i++) {
		w[i] = 0;
	}
	for (int i = 0;i < n;i++) {
		int a;
		cin >> a;
		w[a]++;
		half += a;
	}
	if (half % 2 != 0) {
		cout << "impossible" << endl;
		return 0;
	}
	half /= 2;
	set<int> s[101];
	s[100].insert(half);
	for (int i = 100;i >= 1;i--) {
		for (int j = 0;j <= w[i];j++) {
			for (set<int>::iterator it = s[i].begin();it != s[i].end();it++) {
				if (*it - i * j==0) {
					cout << "possible" << endl;
					return 0;
				}
				else if (*it - i * j > 0) {
					s[i - 1].insert(*it - i * j);
				}
			}
		}
	}
	cout << "impossible" << endl;
	return 0;
}
0