結果

問題 No.4 おもりと天秤
ユーザー konchanksukonchanksu
提出日時 2020-04-27 15:56:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 423 ms / 5,000 ms
コード長 423 bytes
コンパイル時間 237 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 26,880 KB
最終ジャッジ日時 2024-05-01 15:16:56
合計ジャッジ時間 4,528 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,752 KB
testcase_01 AC 29 ms
10,624 KB
testcase_02 AC 36 ms
10,880 KB
testcase_03 AC 32 ms
10,624 KB
testcase_04 AC 37 ms
10,880 KB
testcase_05 AC 333 ms
19,584 KB
testcase_06 AC 29 ms
10,752 KB
testcase_07 AC 329 ms
19,584 KB
testcase_08 AC 30 ms
10,752 KB
testcase_09 AC 423 ms
26,880 KB
testcase_10 AC 358 ms
20,736 KB
testcase_11 AC 30 ms
10,624 KB
testcase_12 AC 29 ms
10,624 KB
testcase_13 AC 30 ms
10,752 KB
testcase_14 AC 29 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 270 ms
19,072 KB
testcase_19 AC 302 ms
18,688 KB
testcase_20 AC 298 ms
18,816 KB
testcase_21 AC 289 ms
18,048 KB
testcase_22 AC 290 ms
18,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

dp = [[False for i in range(0, full * 2 + 1)] for j in range(N + 1)]
dp[0][full] = True


for i in range(N):
    for j in range(-full, full + 1):
        if dp[i][j]:
            dp[i + 1][j + W[i]] = True
            dp[i + 1][j - W[i]] = True
    
print('possible' if dp[N][full] else 'impossible')
0