結果

問題 No.1594 Three Classes
ユーザー ProgrammerryokiProgrammerryoki
提出日時 2021-07-09 22:13:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,164 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 11,024 KB
実行使用メモリ 12,648 KB
最終ジャッジ日時 2023-09-14 09:24:14
合計ジャッジ時間 5,262 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
12,648 KB
testcase_01 AC 15 ms
8,252 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 16 ms
8,152 KB
testcase_05 AC 26 ms
8,252 KB
testcase_06 WA -
testcase_07 AC 14 ms
8,180 KB
testcase_08 AC 34 ms
8,260 KB
testcase_09 AC 34 ms
8,244 KB
testcase_10 AC 27 ms
8,284 KB
testcase_11 AC 53 ms
8,300 KB
testcase_12 AC 25 ms
8,320 KB
testcase_13 AC 14 ms
8,316 KB
testcase_14 AC 17 ms
8,264 KB
testcase_15 AC 185 ms
8,144 KB
testcase_16 AC 16 ms
8,332 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import combinations

N = int(input())
E = [int(i) for i in input().split()]
se = set(E)
SE = sum(E)
if SE % 3 != 0:
    print("No")
    exit()

used = set()
def recur(cur, group):
    if group == 3:
        print("Yes")
        exit()
    for e in se - set(used):
        if e + cur < SE // 3:
            used.add(e)
            recur(cur + e, group)
            used.remove(e)
        elif e + cur == SE // 3:
            used.add(e)
            recur(0, group+1)
            used.remove(e)
        elif e + cur > SE // 3:
            return

recur(0, 0)
print("No")

# from itertools import permutations
#
# N = int(input())
# E = [int(i) for i in input().split()]
# se = sum(E)
# if se % 3 != 0:
#     print("No")
#     exit()
#
# def possible(arr):
#     cur = 0
#     count = 0
#     for i in arr:
#         if i + cur < se // 3:
#             cur += i
#         elif i + cur == se // 3:
#             cur = 0
#             count += 1
#         elif i + cur > se//3:
#             return False
#     return count == 3 and cur == 0
#
# for per in permutations(E, N):
#     if possible(per):
#         print("Yes")
#         exit()
# print("No")
0