結果

問題 No.10 +か×か
ユーザー vwxyzvwxyz
提出日時 2021-06-28 17:06:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 384 ms / 5,000 ms
コード長 1,194 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 133,444 KB
最終ジャッジ日時 2023-08-21 06:34:04
合計ジャッジ時間 5,182 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 259 ms
91,288 KB
testcase_01 AC 258 ms
91,536 KB
testcase_02 AC 258 ms
91,464 KB
testcase_03 AC 383 ms
133,380 KB
testcase_04 AC 345 ms
119,956 KB
testcase_05 AC 256 ms
91,452 KB
testcase_06 AC 384 ms
133,444 KB
testcase_07 AC 343 ms
120,220 KB
testcase_08 AC 291 ms
101,492 KB
testcase_09 AC 293 ms
105,876 KB
testcase_10 AC 261 ms
91,852 KB
testcase_11 AC 265 ms
91,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
from collections import Counter, deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines

N=int(readline())
total=int(readline())
A=list(map(int,readline().split()))
dp=[[False]*(total+1) for i in range(N)]
dp[N-1][total]=True
for i in range(N-2,-1,-1):
    a=A[i+1]
    for t in range(total+1):
        if dp[i+1][t]:
            if 0<=t-a:
                dp[i][t-a]=True
            if t%a==0:
                dp[i][t//a]=True
ans_lst=[]
s=A[0]
for i in range(1,N):
    a=A[i]
    if s+a<=total and dp[i][s+a]:
        s+=a
        ans_lst.append('+')
    else:
        s*=a
        ans_lst.append('*')
print(*ans_lst,sep='')
0