結果

問題 No.4 おもりと天秤
ユーザー konchanksukonchanksu
提出日時 2020-04-27 15:56:30
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 296 ms / 5,000 ms
コード長 423 bytes
コンパイル時間 673 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 24,364 KB
最終ジャッジ日時 2023-08-14 02:12:24
合計ジャッジ時間 4,337 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
7,804 KB
testcase_01 AC 12 ms
8,196 KB
testcase_02 AC 16 ms
8,420 KB
testcase_03 AC 17 ms
8,280 KB
testcase_04 AC 18 ms
8,408 KB
testcase_05 AC 240 ms
17,176 KB
testcase_06 AC 13 ms
7,860 KB
testcase_07 AC 272 ms
17,100 KB
testcase_08 AC 13 ms
8,156 KB
testcase_09 AC 296 ms
24,364 KB
testcase_10 AC 274 ms
18,204 KB
testcase_11 AC 15 ms
7,844 KB
testcase_12 AC 13 ms
7,812 KB
testcase_13 AC 13 ms
7,876 KB
testcase_14 AC 12 ms
7,984 KB
testcase_15 AC 12 ms
7,772 KB
testcase_16 AC 13 ms
7,864 KB
testcase_17 AC 12 ms
7,812 KB
testcase_18 AC 199 ms
16,456 KB
testcase_19 AC 215 ms
16,072 KB
testcase_20 AC 213 ms
16,232 KB
testcase_21 AC 218 ms
15,644 KB
testcase_22 AC 212 ms
15,536 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