結果

問題 No.1105 Many Triplets
ユーザー もりを
提出日時 2020-07-03 22:39:15
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 468 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-09-17 04:19:22
合計ジャッジ時間 1,882 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int,input().split()))
M = 10 ** 9 + 7

p = [1, 1, 0, -3, -9, -18]
q = [-1, -2, -3, -3, 0, 9]
r = [0, 1, 3, 6, 9, 9]

def g(n, l):
    if n >= 6:
        return pow(M - 27, n // 6, M) * g(n % 6, l) % M
    return l[n] if l[n] >= 0 else M + l[n]

ll = [g(n - 2, l) for l in (p, q, r)]

res = []
for k in range(3):
    cnt = 0
    for j, i in enumerate(ll):
        cnt += i * a[(j + k) % 3]
        cnt %= M
    res.append(cnt)
print(*res)
0