結果

問題 No.1594 Three Classes
ユーザー atjh16atjh16
提出日時 2021-09-12 15:53:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 639 bytes
コンパイル時間 1,710 ms
コンパイル使用メモリ 169,588 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 00:43:51
合計ジャッジ時間 2,623 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int n, t = 0;
int e[12];
bool f = 0;

int main()
{
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		cin >> e[i];
		t += e[i];
	}

	if (t % 3 == 0) {
		sort(e, e + n);

		if (e[n - 1] <= t / 3) {
			for (int i = 1; i < 531441; i++) {
				int u = i, a = t, b = 0, c = 0, j = 0;

				while (u > 0) {
					if (u % 3 == 1) {
						a -= e[j];
						b += e[j];
					}
					else if (u % 3 == 2) {
						a -= e[j];
						c += e[j];
					}

					u /= 3;
					j++;
				}

				if (a == b && a == c) {
					f = 1;
					break;
				}
			}
		}
	}

	if(f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
0