結果

問題 No.1594 Three Classes
ユーザー qibqib
提出日時 2023-04-16 01:25:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 497 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 62,920 KB
最終ジャッジ日時 2024-04-19 17:00:40
合計ジャッジ時間 2,164 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
60,508 KB
testcase_01 AC 34 ms
52,872 KB
testcase_02 AC 32 ms
52,804 KB
testcase_03 AC 39 ms
60,616 KB
testcase_04 AC 34 ms
52,672 KB
testcase_05 AC 45 ms
61,188 KB
testcase_06 AC 40 ms
61,076 KB
testcase_07 AC 40 ms
61,496 KB
testcase_08 AC 42 ms
62,920 KB
testcase_09 AC 41 ms
61,320 KB
testcase_10 AC 41 ms
61,184 KB
testcase_11 AC 43 ms
61,168 KB
testcase_12 AC 42 ms
61,808 KB
testcase_13 AC 34 ms
52,804 KB
testcase_14 AC 40 ms
61,384 KB
testcase_15 AC 39 ms
61,364 KB
testcase_16 AC 40 ms
61,028 KB
testcase_17 AC 39 ms
60,304 KB
testcase_18 AC 34 ms
52,008 KB
testcase_19 AC 33 ms
53,248 KB
testcase_20 AC 37 ms
60,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
e = list(map(int, input().split()))

s = sum(e)
if s % 3 != 0:
  print("No")
  exit()

score = [0 for _ in range(1 << n)]
for mask in range(1 << n):
  cnt = 0
  for i in range(n):
    if (mask >> i) & 1 != 0:
      cnt += e[i]

  score[mask] = cnt

for mask in range(1 << n):
  if score[mask] == s // 3:
    sub = ((1 << n) - 1) & (~ mask)
    cur = sub
    while cur > 0:
      cur = (cur - 1) & sub
      if score[cur] == s // 3:
        print("Yes")
        exit()

print("No")
0