結果

問題 No.4 おもりと天秤
ユーザー rocoderrocoder
提出日時 2017-08-03 08:32:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 753 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-20 01:25:45
合計ジャッジ時間 1,739 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

# your code goes here
N=int(input ())
W=[int(i) for i in input (). split ()]
H=0
nd=0
for i in range (N):
    H+=W[i]
if H%2==1:
    nd=2
else:
    H//=2
    W.sort(reverse=True)
    H-=W[0]
    W.pop(0)
    N-=1
if H<0:
    nd=2
U=0
i=0
S=[0]*N
while nd<1:
    while i<N and U<H:
        S[i]=1
        U+=W[0]
        i+=1
    if U==H:
        nd=1
    elif i<N:
        i-=1
        S[i]=0
        U-=W[i]
        i+=1
    else:
        i-=1
        while i>=0 and S[i]==1:
            S[i]=0
            U-=W[i]
            i-=1
        while i>=0 and S[i]==0:
            i-=1
        if i<0:
            nd=2
        else:
            S[i]=0
            U-=W[i]
            i+=1
if nd==2:
    p="impossible"
elif nd==1:
     p="possible"
print (p)
0