結果

問題 No.265 数学のテスト
ユーザー chocorusk
提出日時 2020-09-19 00:06:40
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 305 ms / 2,000 ms
コード長 1,317 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 17,280 KB
最終ジャッジ日時 2024-06-22 11:57:28
合計ジャッジ時間 3,545 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
n=int(readline())
d=int(readline())
s=readline().rstrip().decode()
def multiply(a, b):
    l=len(a)
    m=len(b)
    c=[0]*(l+m-1)
    for i, x in enumerate(a):
        for j, y in enumerate(b):
            c[i+j]+=x*y
    return c
def add(a, b):
    l=len(a)
    m=len(b)
    c=[0]*(max(l, m))
    for i, x in enumerate(a):
        c[i]+=x
    for i, x in enumerate(b):
        c[i]+=x
    return c
i=0
def val():
    global i
    if s[i]=='x':
        i+=1
        return [0, 1]
    elif s[i]=='d':
        i+=2
        p=expr()
        i+=1
        return [(i+1)*x for i, x in enumerate(p[1:])]
    else:
        v=ord(s[i])-ord('0')
        i+=1
        return [v]
def mul():
    global i
    res=val()
    while True:
        if i==n:
            break
        if s[i]=='*':
            i+=1
            p=val()
            res=multiply(res, p)
        else:
            break
    return res
def expr():
    global i
    res=mul()
    while True:
        if i==n:
            break
        if s[i]=='+':
            i+=1
            p=mul()
            res=add(res, p)
        else:
            break
    return res
p=expr()
p+=[0]*(d+1-len(p))
print(' '.join(map(str, p)))
0