結果
| 問題 |
No.1036 Make One With GCD 2
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 21:07:33 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 782 bytes |
| コンパイル時間 | 342 ms |
| コンパイル使用メモリ | 82,228 KB |
| 実行使用メモリ | 191,952 KB |
| 最終ジャッジ日時 | 2025-06-12 21:09:09 |
| 合計ジャッジ時間 | 17,760 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 34 TLE * 1 -- * 6 |
ソースコード
import sys
from math import gcd
from collections import defaultdict
def main():
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
total = 0
prev_gcds = defaultdict(int)
for num in a:
curr_gcds = defaultdict(int)
# Process each GCD from the previous step
for g, cnt in prev_gcds.items():
new_g = gcd(g, num)
curr_gcds[new_g] += cnt
# Add the subarray consisting of just the current number
curr_gcds[num] += 1
# Check if any GCD is 1 and add to total
if 1 in curr_gcds:
total += curr_gcds[1]
# Update prev_gcds for the next iteration
prev_gcds = curr_gcds
print(total)
if __name__ == "__main__":
main()
gew1fw