結果

問題 No.1097 Remainder Operation
ユーザー stngstng
提出日時 2022-06-16 22:09:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 85,112 KB
最終ジャッジ日時 2024-04-16 11:44:58
合計ジャッジ時間 4,264 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,096 KB
testcase_01 AC 38 ms
52,096 KB
testcase_02 AC 38 ms
52,608 KB
testcase_03 AC 38 ms
52,864 KB
testcase_04 AC 38 ms
52,992 KB
testcase_05 AC 38 ms
52,224 KB
testcase_06 AC 38 ms
52,480 KB
testcase_07 AC 79 ms
76,924 KB
testcase_08 AC 78 ms
77,056 KB
testcase_09 AC 81 ms
76,612 KB
testcase_10 AC 78 ms
76,800 KB
testcase_11 AC 77 ms
77,056 KB
testcase_12 AC 132 ms
84,480 KB
testcase_13 AC 139 ms
84,864 KB
testcase_14 AC 137 ms
84,764 KB
testcase_15 AC 138 ms
84,764 KB
testcase_16 AC 135 ms
84,608 KB
testcase_17 AC 134 ms
85,112 KB
testcase_18 AC 124 ms
83,200 KB
testcase_19 AC 136 ms
83,440 KB
testcase_20 AC 133 ms
83,200 KB
testcase_21 AC 135 ms
83,456 KB
testcase_22 AC 136 ms
83,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
k = [int(input())-1 for i in range(q)]

dp = [-1]*(n)
val = [-1]*(n+1)
#dp[0] = 0
x = 0

for i in range(n+1):
    tmp = x%n
    x += a[tmp]
    val[i] = x
    #print(tmp,tmp,tmp)
    if dp[tmp] != -1:
        loop = i - dp[tmp]
        idx = dp[tmp]
        break
    dp[tmp] = i
    #print(tmp,i)
    
#print(loop,idx)
#print(dp,val)

lval = val[idx+loop] - val[idx]
#print(lval,"lval")

for i in range(q):
    if k[i] <= n and val[k[i]] != -1:
        print(val[k[i]])
    else:
        cnt = (k[i]-idx)//loop
        #print(k[i]-lval*cnt-idx)
        ans = lval*cnt+val[k[i]-loop*cnt]
        print(ans)
        
0