結果

問題 No.4 おもりと天秤
ユーザー phtmscgphtmscg
提出日時 2019-03-29 17:59:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 650 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-24 16:41:04
合計ジャッジ時間 7,467 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

N = int(input())
W = list(map(int,input().split()))
w = int(sum(W)/2)

def ballance(i):
    weight = 0
    wsum = [0]*N
    wlist = [0]*N
    while True:
        while weight < w and i < N:
            weight += W[i]
            wsum[i] = weight
            wlist[N-i-1] = 1
            i += 1
        if weight == w:
            return 'possible'
        elif wlist.count(2) != N and i < N:
            wlist[N-i] = 0
            i = wlist.index(1)
            weight = wsum[i]
            wlist[i] = 2
            i += 1
        else:
            break
    return 'impossible'

if w*2 != sum(W):
    print('impossible')
else:
    print(ballance(0))
0