結果

問題 No.1036 Make One With GCD 2
ユーザー maspymaspy
提出日時 2020-04-25 16:35:09
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 679 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 151,712 KB
最終ジャッジ日時 2024-04-25 10:37:26
合計ジャッジ時間 51,263 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,341 ms
151,324 KB
testcase_01 AC 909 ms
145,064 KB
testcase_02 AC 1,130 ms
146,908 KB
testcase_03 AC 644 ms
79,692 KB
testcase_04 AC 736 ms
107,412 KB
testcase_05 AC 542 ms
44,472 KB
testcase_06 AC 536 ms
44,472 KB
testcase_07 AC 691 ms
87,692 KB
testcase_08 AC 654 ms
79,168 KB
testcase_09 AC 1,064 ms
142,664 KB
testcase_10 AC 1,030 ms
136,824 KB
testcase_11 AC 1,072 ms
145,332 KB
testcase_12 AC 1,031 ms
137,360 KB
testcase_13 AC 1,231 ms
140,708 KB
testcase_14 AC 1,196 ms
142,980 KB
testcase_15 AC 1,147 ms
136,460 KB
testcase_16 AC 1,153 ms
136,484 KB
testcase_17 AC 1,181 ms
140,636 KB
testcase_18 AC 535 ms
44,220 KB
testcase_19 AC 541 ms
44,220 KB
testcase_20 AC 537 ms
44,212 KB
testcase_21 AC 551 ms
44,216 KB
testcase_22 AC 1,160 ms
134,824 KB
testcase_23 AC 991 ms
109,768 KB
testcase_24 AC 1,192 ms
138,588 KB
testcase_25 AC 1,127 ms
129,936 KB
testcase_26 AC 1,156 ms
133,200 KB
testcase_27 AC 534 ms
44,212 KB
testcase_28 AC 563 ms
44,220 KB
testcase_29 AC 561 ms
44,220 KB
testcase_30 AC 554 ms
43,972 KB
testcase_31 AC 546 ms
44,084 KB
testcase_32 AC 540 ms
44,352 KB
testcase_33 AC 535 ms
43,964 KB
testcase_34 AC 532 ms
44,216 KB
testcase_35 AC 538 ms
43,972 KB
testcase_36 AC 541 ms
44,468 KB
testcase_37 AC 550 ms
43,968 KB
testcase_38 AC 1,124 ms
146,664 KB
testcase_39 AC 1,621 ms
145,872 KB
testcase_40 AC 980 ms
110,092 KB
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N = int(readline())
A = np.array(read().split() + [1], np.int64)

# sparse table
sp = [np.ones(N + 1, np.int64) for _ in range(20)]
sp[0] = A
for n in range(1, 20):
    dx = 1 << (n - 1)
    sp[n][:-dx] = np.gcd(sp[n - 1][:-dx], sp[n - 1][dx:])

# [L,R) の gcd は 1 ではない。のうちで R を 最大化
L = np.arange(N)
R = L.copy()
G = np.zeros(N, np.int64)
for n in range(19, -1, -1):
    G1 = np.gcd(G, sp[n][R])
    go = G1 != 1
    R[go] += 1 << n
    G[go] = G1[go]

ng = (R - L).sum()
total = N * (N + 1) // 2
print(total - ng)
0