結果

問題 No.265 数学のテスト
ユーザー mkawa2
提出日時 2020-01-31 14:15:34
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,243 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 82,244 KB
実行使用メモリ 848,756 KB
最終ジャッジ日時 2024-09-17 06:50:49
合計ジャッジ時間 4,667 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other MLE * 1 -- * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline()[:-1]

def main():
    def cal(s):
        res = [0] * (d + 1)
        i = 0
        inpar = 0   # いくつのd{}に囲まれているか
        isone=True  # 単項式かどうか
        for j,c in enumerate(s):
            if c==43 and inpar==0:
                ret = cal(s[i:j])
                for k in range(d + 1): res[k] += ret[k]
                i = j + 1
                isone=False
            if c == 123: inpar += 1
            if c == 125: inpar -= 1
        if isone:
            # 微分のとき
            if s[0] == 100:
                ret = cal(s[2:-1])
                for i, a in enumerate(ret[1:], 1):
                    res[i - 1] = a * i
            # 累乗の計算のとき
            else:
                a = 1
                x = 0
                for c in s:
                    if 48 <= c <= 57: a = c - 48
                    if c == 120: x += 1
                res[x] = a
        else:
            ret = cal(s[i:])
            for k in range(d + 1): res[k] += ret[k]
        return res

    n = II()
    d = II()
    s = SI()
    s=[ord(c) for c in s]
    print(*cal(s))

main()
0