結果

問題 No.1594 Three Classes
ユーザー Kenneth YongKenneth Yong
提出日時 2021-07-09 22:52:15
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 13,337 ms
コンパイル使用メモリ 433,128 KB
実行使用メモリ 51,844 KB
最終ジャッジ日時 2024-04-28 00:33:00
合計ジャッジ時間 18,205 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 270 ms
51,572 KB
testcase_01 AC 266 ms
51,696 KB
testcase_02 AC 263 ms
51,500 KB
testcase_03 AC 262 ms
51,792 KB
testcase_04 AC 264 ms
51,572 KB
testcase_05 AC 264 ms
51,844 KB
testcase_06 AC 266 ms
51,596 KB
testcase_07 AC 276 ms
51,700 KB
testcase_08 AC 265 ms
51,664 KB
testcase_09 AC 266 ms
51,720 KB
testcase_10 AC 265 ms
51,836 KB
testcase_11 AC 281 ms
51,716 KB
testcase_12 AC 279 ms
51,816 KB
testcase_13 AC 271 ms
51,744 KB
testcase_14 AC 272 ms
51,844 KB
testcase_15 AC 279 ms
51,484 KB
testcase_16 AC 266 ms
51,520 KB
testcase_17 AC 287 ms
51,696 KB
testcase_18 AC 289 ms
51,696 KB
testcase_19 AC 256 ms
51,564 KB
testcase_20 AC 260 ms
51,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fun main() {
	val n = readLine()!!.toInt();
	val list = readLine()!!.split(" ").map {it -> it.toLong()};
	var sum = list.reduce {p, q -> p + q};
	if (sum % 3L != 0L) {
		println("No");
		return;
	}
	sum /= 3;
	
	for (i in 1 until 1.shl(n)) {
		var current = 0L;
		for (j in 0 until n) {
			if ((i and 1.shl(j)) > 0) {
				current += list[j];
			}
		}
		if (current == 2 * sum) {
			var mask = i;
			while (mask > 0) {
				current = 0L;
				for (j in 0 until n) {
					if ((mask and 1.shl(j)) > 0) {
						current += list[j];
					}
				}
				if (current == sum) {
					println("Yes");
					return;
				}
				
				mask = (mask - 1) and i;
			}
		}
	}
	
	println("No");
}
/*
C:\Users\kenne\OneDrive\Desktop\competitive_programming\kotlinmain.kt
*/
0