結果
問題 | No.4 おもりと天秤 |
ユーザー |
![]() |
提出日時 | 2020-12-04 07:09:23 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 58 ms / 5,000 ms |
コード長 | 775 bytes |
コンパイル時間 | 560 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 64,128 KB |
最終ジャッジ日時 | 2024-09-14 17:18:58 |
合計ジャッジ時間 | 2,245 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) N = I() W = [0]+LI() s = sum(W) if s % 2 == 1: print('impossible') exit() X = s//2 dp = [[0]*(X+1) for _ in range(N+1)] dp[0][0] = 1 for i in range(1,N+1): w = W[i] for j in range(X+1): if j >= w: dp[i][j] = dp[i-1][j] | dp[i-1][j-w] print('possible' if dp[-1][-1] else 'impossible')