結果
問題 | No.4 おもりと天秤 |
ユーザー |
|
提出日時 | 2020-03-11 11:33:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 76 ms / 5,000 ms |
コード長 | 1,712 bytes |
コンパイル時間 | 192 ms |
コンパイル使用メモリ | 81,904 KB |
実行使用メモリ | 69,888 KB |
最終ジャッジ日時 | 2024-11-16 00:05:38 |
合計ジャッジ時間 | 2,641 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
from heapq import heappush, heappop, heapify from collections import deque, defaultdict, Counter import itertools from itertools import permutations, combinations, accumulate import sys import bisect import string import math import time def I(): return int(input()) def MI(): return map(int, input().split()) def S(): return input() def MS(): return map(str, input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i)-1 for i in input().split()] def StoI(): return [ord(i)-97 for i in input()] def ItoS(nn): return chr(nn+97) def input(): return sys.stdin.readline().rstrip() def show(*inp, end='\n'): if show_flg: print(*inp, end=end) def print_matrix(mat): for i in range(len(mat)): print(*mat[i]) YNL = {False: 'No', True: 'Yes'} YNU = {False: 'NO', True: 'YES'} MOD = 10**9+7 inf = float('inf') IINF = 10**10 l_alp = string.ascii_lowercase u_alp = string.ascii_uppercase ts = time.time() # sys.setrecursionlimit(10**6) nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] # show_flg = True show_flg = False def main(): N = I() W = LI() total = sum(W) if total % 2 == 1: print('impossible') return half = total // 2 dp = [0] * (half+1) dp[0] = 1 for i in range(N): dp_next = [0] * (half+1) dp_next[0] = 1 for j in range(half+1): if dp[j] == 1: dp_next[j] = 1 if j + W[i] <= half: dp_next[j+W[i]] = 1 # print(i, dp_next) dp = dp_next if dp[half] == 0: print('impossible') else: print('possible') if __name__ == '__main__': main()