結果

問題 No.4 おもりと天秤
ユーザー piconic_Xpiconic_X
提出日時 2016-08-20 00:30:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 943 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-04-25 08:38:06
合計ジャッジ時間 1,716 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 30 ms
10,752 KB
testcase_02 AC 29 ms
10,752 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 68 ms
11,776 KB
testcase_06 AC 27 ms
10,752 KB
testcase_07 AC 67 ms
11,904 KB
testcase_08 AC 27 ms
10,752 KB
testcase_09 AC 26 ms
10,752 KB
testcase_10 WA -
testcase_11 AC 27 ms
10,752 KB
testcase_12 WA -
testcase_13 AC 27 ms
10,752 KB
testcase_14 WA -
testcase_15 AC 26 ms
10,752 KB
testcase_16 WA -
testcase_17 AC 26 ms
10,752 KB
testcase_18 AC 32 ms
11,264 KB
testcase_19 WA -
testcase_20 AC 66 ms
11,648 KB
testcase_21 AC 61 ms
11,648 KB
testcase_22 AC 60 ms
11,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def search(N, ws, Sum):
    q = [Sum]
    s = [0]
    while q:
        target = q.pop(0)
        start = s.pop(0)
        for i in range(start, N):
            d = target - ws[i]
            if d == 0:
                res = True
            elif d < 0:
                if i == N-1:
                    res = False
                else:
                    continue
            elif d > 0:
                q_ = [target - ws[j] for j in range(i, N)]
                q.extend(q_)
                s_ = [j for j in range(i, N)]
                s.extend(s_)
                del q[0:N-i-1]
                break
    return res

def main():
    N = int(input())
    ws = list(map(int, input().split()))
    ws.sort()
    ws.reverse()
    ws_sum = sum(ws)
    if ws_sum % 2 == 0:
        Sum = ws_sum // 2
        res = search(N, ws, Sum)
    else:
        res = False
    if res:
        print('possible')
    else:
        print('impossible')

main()
0