#26102: 想問怎麼讓他更快(第4個測資3S)


zhengyouli547@gmail.com (hahaha)


while True:

    try:

        t=int(input())

        a=list(map(int,input().split()))

        for f in range (t):

            ans=sum(a[0:1+f])

            print(ans,end=' ')

    except:

        break

#26572: Re:想問怎麼讓他更快(第4個測資3S)


k333hoisi@gmail.com (何子斌)


while True:

    try:

        t=int(input())

        a=list(map(int,input().split()))

        for f in range (t):

            ans=sum(a[0:1+f])

            print(ans,end=' ')

    except:

        break


因為你每一回都從頭累加,

直接在迴圈快開一個變數=0 紀錄上一回累加的等於多少,下一回繼續使用這個變數

#26573: Re:想問怎麼讓他更快(第4個測資3S)


406490150@gms.tku.edu.tw (我是朱朱)


while True:

    try:

        t=int(input())

        a=list(map(int,input().split()))

        for f in range (t):

            ans=sum(a[0:1+f])

            print(ans,end=' ')

    except:

        break


itertools.accumulate

#26632: Re:想問怎麼讓他更快(第4個測資3S)


zhengyouli547@gmail.com (hahaha)


雖然之前就過了,不過有一點我很好奇,為甚麼會知道那麼多內建模組XD

是特地上官網找的嗎