結果

問題 No.4 おもりと天秤
ユーザー silversmithsilversmith
提出日時 2019-05-03 19:40:52
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 517 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 15,744 KB
最終ジャッジ日時 2023-08-30 05:51:01
合計ジャッジ時間 13,252 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 280 ms
11,164 KB
testcase_01 AC 568 ms
11,300 KB
testcase_02 AC 1,855 ms
11,296 KB
testcase_03 AC 1,201 ms
11,160 KB
testcase_04 AC 1,830 ms
11,228 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

c_idx = 10 ** 5
dp = [False] * (2 * c_idx)
dp[c_idx + W[0]] = True
dp[c_idx - W[0]] = True
dp2 = [False] * len(dp)
for i in range(N -1):
    for x in range(2* c_idx):
        if x < W[i+1]:
            dp2[x] = dp[x + W[i+1]]
        elif x + W[i+1] > len(dp) -1:
            dp2[x] = dp[x - W[i+1]]
        else:
            dp2[x] = dp[x + W[i+1]] or dp[x - W[i+1]]
    dp, dp2 = dp2, dp

if dp[c_idx] == True:
    print('possible')
else:
    print('impossible')
0