結果

問題 No.265 数学のテスト
ユーザー titiatitia
提出日時 2022-10-18 05:07:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,369 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 11,048 KB
実行使用メモリ 16,296 KB
最終ジャッジ日時 2023-09-11 01:16:03
合計ジャッジ時間 2,796 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
16,296 KB
testcase_01 AC 66 ms
12,672 KB
testcase_02 AC 37 ms
8,780 KB
testcase_03 AC 35 ms
8,620 KB
testcase_04 AC 34 ms
8,596 KB
testcase_05 AC 37 ms
8,608 KB
testcase_06 AC 35 ms
8,716 KB
testcase_07 AC 38 ms
8,676 KB
testcase_08 AC 41 ms
8,796 KB
testcase_09 AC 32 ms
8,648 KB
testcase_10 AC 33 ms
8,776 KB
testcase_11 AC 36 ms
8,556 KB
testcase_12 AC 16 ms
8,244 KB
testcase_13 AC 26 ms
8,512 KB
testcase_14 AC 21 ms
8,492 KB
testcase_15 AC 15 ms
8,392 KB
testcase_16 AC 19 ms
8,276 KB
testcase_17 AC 16 ms
8,268 KB
testcase_18 AC 16 ms
8,272 KB
testcase_19 AC 16 ms
8,404 KB
testcase_20 AC 16 ms
8,412 KB
testcase_21 AC 16 ms
8,336 KB
testcase_22 AC 21 ms
8,148 KB
testcase_23 AC 16 ms
8,360 KB
testcase_24 AC 16 ms
8,332 KB
testcase_25 AC 25 ms
8,592 KB
testcase_26 AC 16 ms
8,336 KB
testcase_27 AC 15 ms
8,332 KB
testcase_28 AC 17 ms
8,380 KB
testcase_29 AC 15 ms
8,240 KB
testcase_30 AC 18 ms
8,380 KB
testcase_31 AC 16 ms
8,284 KB
testcase_32 AC 16 ms
8,336 KB
testcase_33 AC 16 ms
8,312 KB
testcase_34 AC 16 ms
8,308 KB
testcase_35 AC 15 ms
8,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)

N=int(input())
d=int(input())
S=input().strip()

D=[-1]*N

Q=[]
for i in range(len(S)):
    if S[i]=="d":
        Q.append(i)
    elif S[i]=="}":
        D[Q[-1]]=i
        Q.pop()
    
def calc(L,R):
    ANS=[0]*12

    ind=L
    score=1
    dim=0
    
    while ind<=R:
        #print(ANS,ind)
        if S[ind]=="d":
            x=D[ind]
            
            X=diff(calc(ind+2,x-1))

            for i in range(len(X)):
                ANS[i]+=X[i]

            ind=x+1
            score=1
            dim=0
            if ind<len(S) and S[ind]=="+":
                ind+=1

        elif S[ind]=="x":
            dim+=1
            
            if ind+1<len(S) and S[ind+1]=="*":
                ind+=2
            else:
                ind+=1

        elif "1"<=S[ind]<="9":
            x=int(S[ind])
            score*=x
            if ind+1<len(S) and S[ind+1]=="*":
                ind+=2
            else:
                ind+=1

        else:
            ANS[dim]+=score
            score=1
            dim=0
            ind+=1

        if ind==R+1 and S[ind-1]!="}":
            ANS[dim]+=score
            break

    return ANS
  

def diff(A):
    #print("!",A)
    ANS=[0]*(len(A)-1)

    for i in range(len(A)):
        ANS[i-1]=i*A[i]

    #print(ANS)

    return ANS
        

print(*calc(0,len(S)-1)[:d+1])
0