結果

問題 No.1594 Three Classes
ユーザー けむけむけむけむ
提出日時 2021-08-15 15:50:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,378 bytes
コンパイル時間 67 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-04-28 00:42:48
合計ジャッジ時間 1,252 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
11,136 KB
testcase_01 AC 29 ms
10,880 KB
testcase_02 AC 28 ms
10,880 KB
testcase_03 AC 26 ms
10,752 KB
testcase_04 AC 25 ms
11,008 KB
testcase_05 AC 27 ms
11,136 KB
testcase_06 AC 25 ms
11,008 KB
testcase_07 AC 26 ms
11,008 KB
testcase_08 AC 26 ms
11,008 KB
testcase_09 AC 28 ms
11,136 KB
testcase_10 AC 26 ms
11,008 KB
testcase_11 AC 25 ms
11,136 KB
testcase_12 AC 26 ms
11,136 KB
testcase_13 AC 25 ms
10,752 KB
testcase_14 AC 26 ms
10,752 KB
testcase_15 AC 26 ms
11,008 KB
testcase_16 AC 26 ms
10,752 KB
testcase_17 AC 26 ms
10,880 KB
testcase_18 AC 30 ms
11,008 KB
testcase_19 AC 26 ms
10,880 KB
testcase_20 AC 27 ms
10,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import combinations

def kurasuwake(N, E):
    Eall = sum(E)
    if Eall % 3 > 0:
        return 'No'
    else:
        Ecl = Eall // 3
        Emax = max(E)
        if Emax > Ecl:
            return 'No'
        else:
            A = P(E, Ecl)
            if A == 'No':
                return 'No'
            else:
                B = P(A, Ecl)
                if B == 'No':
                    return 'No'
                else:
                    PC = sum(B)
                    if PC == Ecl:
                        return 'Yes'
                    else:
                        return 'No'

def P(E, Ecl):
    N = len(E)
    li = sorted(E)
    P = 0 + li[-1]
    li.pop(-1)
    if P == Ecl:
        return li
    comij = []
    for i in range(1, N - 1):
        comi = list(combinations(li, i))
        if P == Ecl:
            break
        for j in range(len(comi)):
            sumij = sum(comi[j])
            if P + sumij == Ecl:
                comij = comi[j]
                P = P + sumij
                break
    if P != Ecl:
        return 'No'
    for k in range(len(comij)):
        for l in range(len(li)):
            if li[l] == comij[k]:
                li.pop(l)
                break
    return li

def main():
    N = int(input())
    E = list(map(int, input().split()))
    print(kurasuwake(N, E))

if __name__ == '__main__':
    main()
0