結果

問題 No.265 数学のテスト
ユーザー damindamin
提出日時 2020-11-04 03:46:01
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,911 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-07-22 09:38:44
合計ジャッジ時間 3,134 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
try:
    import os
    f = open('input.txt', 'r')
    sys.stdin = f
except FileNotFoundError:
    None
from math import sqrt, ceil
from collections import deque, Counter, defaultdict
# defaultdict(int)
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
from fractions import Fraction as frac  #frac(a,b)で正確なa/b
# @lru_cache(maxsize=10**10)
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########

n= int(input())
d=int(input())
s=input()
now=0
# ji = {i:0 for i in range(d+1)}

def gousei(di,dii):
    return {i:di[i]+dii[i] for i in range(d+1)}
def bibun(di):
    ans = {i:0 for i in range(d+1)}
    for i in range(d):
        ans[i] = di[i+1]*(i+1)
    ans[d]=0
    return ans
# print(gousei({0:3,1:2,2:4,3:0,},{0:2,1:2,2:4,3:4}))
# print(bibun({0:0,1:0}))


def shin():
    global now
    ans = expr()
    while now<n and s[now]=="+":
        now+=1
        ans = gousei(ans,expr())
    # print(ans,now)
    return ans

def expr():
    global now
    # jitmp = {i:0 for i in range(d+1)}
    if s[now]=="d":
        now+=2
        jit = shin()
        now+=1
        return bibun(jit)
    else:
        return term()

def term():
    global now
    ji=0 ; kei=1
    ans = {i:0 for i in range(d+1)}
    if s[now]=="x":
        ji+=1
    else:
        kei*=int(s[now])
    now+=1
    while now< n and s[now]=="*":
        now+=1
        if s[now]=="x":
            ji+=1
            now+=1
        else:
            kei*=int(s[now])
            now+=1
    ans[ji]=kei
    return ans

last = shin()
print(*[last[i] for i in range(d+1)])
0