結果

問題 No.265 数学のテスト
ユーザー mkawa2
提出日時 2020-01-31 14:02:49
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,359 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 142,464 KB
最終ジャッジ日時 2024-09-17 06:50:35
合計ジャッジ時間 6,609 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other TLE * 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 = j = 0
        inpar = 0   # いくつのd{}に囲まれているか
        while j < len(s):
            while s[j] != 43 or inpar > 0:
                j += 1
                if j == len(s): break
                if s[j] == 123: inpar += 1
                if s[j] == 125: inpar -= 1
            # 単項式だった場合
            if i == 0 and j == len(s):
                # 微分のとき
                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
                return res
            # 項ごとに再計算して次数ごとに係数を合計する
            ret = cal(s[i:j])
            for k in range(d + 1): res[k] += ret[k]
            i = j = j + 1
        return res

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

main()
0