結果
| 問題 |
No.1594 Three Classes
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:22:42 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 74 ms / 2,000 ms |
| コード長 | 1,165 bytes |
| コンパイル時間 | 201 ms |
| コンパイル使用メモリ | 82,852 KB |
| 実行使用メモリ | 68,096 KB |
| 最終ジャッジ日時 | 2025-03-31 17:23:28 |
| 合計ジャッジ時間 | 2,012 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
import sys
def main():
N = int(sys.stdin.readline())
E = list(map(int, sys.stdin.readline().split()))
sum_total = sum(E)
if sum_total % 3 != 0:
print("No")
return
target = sum_total // 3
for e in E:
if e > target:
print("No")
return
E.sort(reverse=True)
def backtrack(index, a, b, c):
if index == N:
return a == target and b == target and c == target
current = E[index]
# Try adding to A
if a < target and a + current <= target:
if backtrack(index + 1, a + current, b, c):
return True
# Try adding to B
if b < target and b + current <= target:
if backtrack(index + 1, a, b + current, c):
return True
# Try adding to C
if c < target and c + current <= target:
if backtrack(index + 1, a, b, c + current):
return True
# None of the options work
return False
if backtrack(0, 0, 0, 0):
print("Yes")
else:
print("No")
if __name__ == "__main__":
main()
lam6er