結果

問題 No.265 数学のテスト
ユーザー yaoshimax
提出日時 2016-05-08 15:49:26
言語 Python2
(2.7.18)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,186 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 6,784 KB
実行使用メモリ 6,784 KB
最終ジャッジ日時 2024-11-24 11:33:28
合計ジャッジ時間 2,537 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(raw_input())
d=int(raw_input())
S=raw_input()

def rec(S,d,depth):
    ans=[0 for i in range(d+1)]
    if depth > 10:
        return ans
    start=0
    while start<len(S):
        if S[start]=='d':
            cnt,end=1,start+2
            while True:
                if S[end]=='{':
                    cnt+=1
                elif S[end]=='}':
                    cnt-=1
                    if cnt==0:
                        break
                end+=1
            ans2=rec(S[start+2:end],d,depth+1)
            for di in range(d):
                ans2[di]=ans2[di+1]*(di+1)
            ans2[d]=0
            ans=[x+y for (x,y) in zip(ans,ans2)]
            start=end+2
        else:
            cnt,coef,end=0,1,start
            while end<len(S):
                if S[end]=='+':
                    break
                elif S[end]=='x':
                    cnt+=1
                elif S[end]>='0' and S[end]<='9':
                    coef=int(S[end])
                end+=1
            ans2=[0 for i in range(d+1)]
            ans2[cnt]=coef
            ans=[x+y for (x,y) in zip(ans,ans2)]
            start=end+1
    return ans

for a in rec(S,d,0):
    print a,
print

0