結果

問題 No.4 おもりと天秤
ユーザー soisusoisu
提出日時 2021-09-20 10:03:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 133 ms / 5,000 ms
コード長 340 bytes
コンパイル時間 1,149 ms
コンパイル使用メモリ 87,228 KB
実行使用メモリ 84,704 KB
最終ジャッジ日時 2023-09-15 08:57:49
合計ジャッジ時間 4,569 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,264 KB
testcase_01 AC 72 ms
71,144 KB
testcase_02 AC 110 ms
75,964 KB
testcase_03 AC 84 ms
75,988 KB
testcase_04 AC 90 ms
75,984 KB
testcase_05 AC 133 ms
84,440 KB
testcase_06 AC 74 ms
71,036 KB
testcase_07 AC 132 ms
84,332 KB
testcase_08 AC 79 ms
75,864 KB
testcase_09 AC 113 ms
75,956 KB
testcase_10 AC 133 ms
84,556 KB
testcase_11 AC 82 ms
75,968 KB
testcase_12 AC 73 ms
71,112 KB
testcase_13 AC 72 ms
71,264 KB
testcase_14 AC 78 ms
75,920 KB
testcase_15 AC 72 ms
71,116 KB
testcase_16 AC 81 ms
75,852 KB
testcase_17 AC 72 ms
70,968 KB
testcase_18 AC 127 ms
84,704 KB
testcase_19 AC 131 ms
84,304 KB
testcase_20 AC 132 ms
84,464 KB
testcase_21 AC 130 ms
84,288 KB
testcase_22 AC 130 ms
84,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

Max=max(W)*N+1
dp=[[False]*Max for i in range(N+1)]
dp[0][0]=True

for i in range(N):
    for j in range(Max):
        if j+W[i]<Max:
            dp[i+1][j+W[i]]|=dp[i][j]
        if abs(j-W[i])<Max:
            dp[i+1][abs(j-W[i])]|=dp[i][j]

print("possible" if dp[N][0] else "impossible")
0