結果

問題 No.4 おもりと天秤
ユーザー kohei2019kohei2019
提出日時 2021-02-02 21:13:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 517 ms / 5,000 ms
コード長 428 bytes
コンパイル時間 1,641 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 16,136 KB
最終ジャッジ日時 2023-09-12 11:24:07
合計ジャッジ時間 6,353 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
8,520 KB
testcase_01 AC 15 ms
8,072 KB
testcase_02 AC 91 ms
9,456 KB
testcase_03 AC 65 ms
8,936 KB
testcase_04 AC 89 ms
9,352 KB
testcase_05 AC 434 ms
15,976 KB
testcase_06 AC 25 ms
8,508 KB
testcase_07 AC 508 ms
16,132 KB
testcase_08 AC 16 ms
8,244 KB
testcase_09 AC 517 ms
16,136 KB
testcase_10 AC 464 ms
16,024 KB
testcase_11 AC 52 ms
8,816 KB
testcase_12 AC 31 ms
8,456 KB
testcase_13 AC 31 ms
8,556 KB
testcase_14 AC 34 ms
8,632 KB
testcase_15 AC 30 ms
8,540 KB
testcase_16 AC 57 ms
8,756 KB
testcase_17 AC 51 ms
8,776 KB
testcase_18 AC 503 ms
16,108 KB
testcase_19 AC 464 ms
16,124 KB
testcase_20 AC 472 ms
15,948 KB
testcase_21 AC 474 ms
16,084 KB
testcase_22 AC 505 ms
16,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
N = int(input())
lsW = list(map(int,input().split()))
sum1 = sum(lsW)
if sum1%2 == 1:
    print('impossible')
    sys.exit()
dp = [[False]*(10000+1) for i in range(N+1)]
dp[0][0] = True
for i in range(N):
    for j in range(10000+1):
        if j - lsW[i] < 0:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = (dp[i][j] or dp[i][j-lsW[i]])
print('possible' if dp[N][sum1//2] else 'impossible')
0