結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
ayame_py
|
| 提出日時 | 2015-10-06 03:24:24 |
| 言語 | Python2 (2.7.18) |
| 結果 |
AC
|
| 実行時間 | 2,014 ms / 5,000 ms |
| コード長 | 533 bytes |
| コンパイル時間 | 136 ms |
| コンパイル使用メモリ | 6,912 KB |
| 実行使用メモリ | 11,076 KB |
| 最終ジャッジ日時 | 2024-06-26 09:20:32 |
| 合計ジャッジ時間 | 20,767 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / 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