結果

問題 No.4 おもりと天秤
ユーザー phtmscg
提出日時 2019-03-29 17:59:43
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 650 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 21,376 KB
最終ジャッジ日時 2024-11-07 01:21:08
合計ジャッジ時間 7,248 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 2 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

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