結果
問題 |
No.265 数学のテスト
|
ユーザー |
![]() |
提出日時 | 2020-01-31 13:51:08 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,869 bytes |
コンパイル時間 | 95 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 32,000 KB |
最終ジャッジ日時 | 2024-09-17 06:50:12 |
合計ジャッジ時間 | 6,737 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | TLE * 1 -- * 31 |
ソースコード
import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def SI(): return sys.stdin.readline()[:-1] def MI(): return map(int, sys.stdin.readline().split()) def MI1(): return map(int1, sys.stdin.readline().split()) def MF(): return map(float, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LI1(): return list(map(int1, sys.stdin.readline().split())) def LF(): return list(map(float, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] dij = [(0, 1), (1, 0), (0, -1), (-1, 0)] def main(): def cal(s): res = [0] * (d + 1) i = j = 0 inpar = 0 # いくつのd{}に囲まれているか while j < len(s): while s[j] != "+" or inpar > 0: j += 1 if j == len(s): break if s[j] == "{": inpar += 1 if s[j] == "}": inpar -= 1 # 単項式だった場合 if i == 0 and j == len(s): # 微分のとき if s[0] == "d": 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 c.isdigit(): a = int(c) if c == "x": 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() print(*cal(s)) main()