結果
| 問題 |
No.1036 Make One With GCD 2
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 14:13:00 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 944 bytes |
| コンパイル時間 | 312 ms |
| コンパイル使用メモリ | 82,288 KB |
| 実行使用メモリ | 163,664 KB |
| 最終ジャッジ日時 | 2025-06-12 14:13:30 |
| 合計ジャッジ時間 | 19,026 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 34 TLE * 1 -- * 6 |
ソースコード
import math
import sys
def main():
input = sys.stdin.read().split()
n = int(input[0])
a = list(map(int, input[1:n+1]))
res = 0
prev_gcds = [] # List of tuples (g, count)
for x in a:
if x == 1:
current_count = sum(cnt for g, cnt in prev_gcds) + 1
res += current_count
prev_gcds = [(1, current_count)]
else:
curr = {}
# Handle current element alone
curr[x] = 1
# Handle previous elements
for g, cnt in prev_gcds:
new_g = math.gcd(g, x)
if new_g in curr:
curr[new_g] += cnt
else:
curr[new_g] = cnt
# Add the count of 1 to the result
res += curr.get(1, 0)
# Update prev_gcds
prev_gcds = list(curr.items())
print(res)
if __name__ == "__main__":
main()
gew1fw