結果

問題 No.4 おもりと天秤
ユーザー konchanksukonchanksu
提出日時 2020-04-27 14:57:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 446 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-05-01 13:07:42
合計ジャッジ時間 2,672 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

N = int(input())
W = list(map(int, input().split()))
full = sum(W)

if full % 2 == 1:
    print('impossible')
    exit()

dp = [-1 for i in range(full + 1)]
half = full // 2
dp[half] = 0

for i in range(N):
    for j in range(full):
        if dp[j] == i:
            if j + W[i] <= full:
                dp[j + W[i]] = i + 1
            if j - W[i] >= 0:
                dp[j - W[i]] = i + 1

print('possible' if dp[half] == N else 'impossible')
0