結果
問題 |
No.265 数学のテスト
|
ユーザー |
![]() |
提出日時 | 2025-04-15 21:46:52 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,641 bytes |
コンパイル時間 | 479 ms |
コンパイル使用メモリ | 82,024 KB |
実行使用メモリ | 295,932 KB |
最終ジャッジ日時 | 2025-04-15 21:48:24 |
合計ジャッジ時間 | 6,846 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 RE * 2 |
ソースコード
def parse_expression(tokens, ptr, d): terms = [] terms.append(parse_term(tokens, ptr, d)) while ptr[0] < len(tokens) and tokens[ptr[0]] == '+': ptr[0] += 1 terms.append(parse_term(tokens, ptr, d)) res = [0] * (d + 1) for term in terms: for i in range(d + 1): res[i] += term[i] return res def parse_term(tokens, ptr, d): factors = [] factors.append(parse_factor(tokens, ptr, d)) while ptr[0] < len(tokens) and tokens[ptr[0]] == '*': ptr[0] += 1 factors.append(parse_factor(tokens, ptr, d)) res = [0] * (d + 1) res[0] = 1 # Initialize with multiplicative identity (1) for factor in factors: temp = [0] * (d + 1) for i in range(d + 1): if res[i] == 0: continue for j in range(d + 1): if i + j > d: continue temp[i + j] += res[i] * factor[j] res = temp.copy() return res def parse_factor(tokens, ptr, d): if ptr[0] >= len(tokens): return [0] * (d + 1) current_char = tokens[ptr[0]] if current_char == 'd': ptr[0] += 1 if ptr[0] >= len(tokens) or tokens[ptr[0]] != '{': return [0] * (d + 1) ptr[0] += 1 level = 1 start = ptr[0] while ptr[0] < len(tokens) and level > 0: if tokens[ptr[0]] == '{': level += 1 elif tokens[ptr[0]] == '}': level -= 1 if level == 0: break ptr[0] += 1 inner_tokens = tokens[start:ptr[0]] ptr[0] += 1 # Consume the closing '}' inner_ptr = [0] inner_poly = parse_expression(inner_tokens, inner_ptr, d) derived_poly = compute_derivative(inner_poly, d) return derived_poly elif current_char == 'x': ptr[0] += 1 poly = [0] * (d + 1) if 1 <= d: poly[1] = 1 return poly elif current_char.isdigit(): val = int(current_char) ptr[0] += 1 poly = [0] * (d + 1) poly[0] = val return poly else: ptr[0] += 1 return [0] * (d + 1) def compute_derivative(poly, d): res = [0] * (d + 1) for j in range(d + 1): if j + 1 <= d: res[j] = (j + 1) * poly[j + 1] return res def main(): import sys input = sys.stdin.read().split() N = int(input[0]) d = int(input[1]) S = input[2] tokens = list(S) ptr = [0] poly = parse_expression(tokens, ptr, d) print(' '.join(map(str, poly))) if __name__ == '__main__': main()