結果
| 問題 | No.4 おもりと天秤 |
| コンテスト | |
| ユーザー |
ayame_py
|
| 提出日時 | 2015-10-06 03:24:24 |
| 言語 | PyPy2 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 134 ms / 5,000 ms |
| コード長 | 533 bytes |
| 記録 | |
| コンパイル時間 | 203 ms |
| コンパイル使用メモリ | 77,492 KB |
| 最終ジャッジ日時 | 2025-12-03 17:16:01 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
# coding: utf-8
import sys
maxW = 100001
N = int(raw_input())
W = map(int, raw_input().split())
#重さの合計が奇数なら終了!
sumW = sum(W)
if sumW % 2 == 1:
print 'impossible'
sys.exit()
dp = [[False for _ in range(maxW)] for _ in range(2)]
dp[0][0] = True
c = 0
for weight in W:
for i in range(maxW):
if dp[c%2][i]== True:
dp[(c+1)%2][i] = True
if i+weight < maxW: dp[(c+1)%2][i+weight] = True
c+=1
if dp[c%2][sumW/2]:
print 'possible'
else:
print 'impossible'
ayame_py