結果

問題 No.1036 Make One With GCD 2
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-03-30 16:19:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 533 ms / 2,000 ms
コード長 811 bytes
コンパイル時間 4,442 ms
コンパイル使用メモリ 207,420 KB
実行使用メモリ 15,464 KB
最終ジャッジ日時 2024-03-30 16:19:54
合計ジャッジ時間 19,045 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 424 ms
15,464 KB
testcase_01 AC 287 ms
15,464 KB
testcase_02 AC 428 ms
15,464 KB
testcase_03 AC 34 ms
8,872 KB
testcase_04 AC 57 ms
14,016 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 111 ms
9,056 KB
testcase_08 AC 91 ms
8,832 KB
testcase_09 AC 318 ms
15,416 KB
testcase_10 AC 290 ms
15,136 KB
testcase_11 AC 318 ms
15,440 KB
testcase_12 AC 292 ms
15,080 KB
testcase_13 AC 528 ms
15,232 KB
testcase_14 AC 533 ms
15,312 KB
testcase_15 AC 495 ms
15,088 KB
testcase_16 AC 506 ms
15,152 KB
testcase_17 AC 514 ms
15,240 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 3 ms
6,676 KB
testcase_21 AC 4 ms
6,676 KB
testcase_22 AC 490 ms
15,000 KB
testcase_23 AC 365 ms
14,048 KB
testcase_24 AC 510 ms
15,160 KB
testcase_25 AC 465 ms
14,896 KB
testcase_26 AC 481 ms
15,016 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 412 ms
15,464 KB
testcase_39 AC 429 ms
15,464 KB
testcase_40 AC 361 ms
14,048 KB
testcase_41 AC 472 ms
15,464 KB
testcase_42 AC 473 ms
15,464 KB
testcase_43 AC 474 ms
15,464 KB
testcase_44 AC 478 ms
15,464 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace atcoder;
using namespace std;
using ll = long long;
ll op(ll a, ll b) {return gcd(a, b);}
ll e() {return 0LL;}
int main() {
	int N;cin >> N;
	vector<ll> A(N + 100, 0);
	for (int i = 1;i <= N;i++) cin >> A[i];
	int r = -1;
	ll ans = 0;
	segtree<ll, op, e> seg(A);
	for (int i = 1;i <= N;i++) {
		if (A[i] == 1) r =-1;
		if (r == -1 or r  <= i - 1) {
			ll g = 0;
			for (int k = i;k <= N;k++) {
				if (gcd(g, A[k]) == 1) break;
				g = gcd(g, A[k]);
				r = k;		
			}
			if (r == -1) {
				ans += N - i + 1;
			} else {
				ans += N - r;
			}
			continue;
		}
		ll now = seg.prod(i, r + 1);
		for (int k = r + 1;k <= N;k++) {
			if (gcd(A[k], now) == 1) break;
			r = k;
			now = gcd(now, A[k]);
		}
		ans += N - r;
	}
	cout << ans << endl;
}
0