結果

問題 No.510 二次漸化式
ユーザー kjnho
提出日時 2017-04-29 00:14:18
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,028 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 15,580 KB
最終ジャッジ日時 2024-09-13 19:32:23
合計ジャッジ時間 5,658 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 4 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict as dd
def main():
    n = int(input())
    Q = int(input())

    Ai = dd(int)
    B = [1]* (n+1)
    X = [0]* (n+1)
    Y = [0]* (n+1)
    for q in range(Q):
        tmp = input()
        if tmp[0] == "a":
            direction, k = tmp.split()
            k = int(k)
            answer = 1
            for key, value in Ai.items():
                if k >= key:
                    answer += value
                    answer %= 10**9 + 7
                else:
                    break
            print(answer)
            continue

        direction, k, param = tmp.split()
        param = int(param)
        k = int(k)
        if direction == "y":
            tmp = B[k+1]**2
            B[k+1] += (param - Y[k]) * B[k]
            Ai[k+2] += X[k+1] * (B[k+1]**2 - tmp)
            Y[k] = param
        elif direction == "x":
            Ai[k+1] += (param - X[k]) * (B[k]**2)
            X[k] = param
        # print("Ai",Ai)
        # print("B",B)


if __name__ == "__main__":
    main()
0