結果

問題 No.1036 Make One With GCD 2
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-03-30 16:12:31
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 784 bytes
コンパイル時間 1,950 ms
コンパイル使用メモリ 159,812 KB
実行使用メモリ 15,364 KB
最終ジャッジ日時 2024-03-30 16:12:50
合計ジャッジ時間 17,669 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 458 ms
15,260 KB
testcase_01 AC 329 ms
15,260 KB
testcase_02 AC 436 ms
15,260 KB
testcase_03 AC 33 ms
8,796 KB
testcase_04 AC 58 ms
13,932 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 298 ms
15,212 KB
testcase_10 AC 275 ms
14,932 KB
testcase_11 AC 302 ms
15,364 KB
testcase_12 AC 278 ms
14,996 KB
testcase_13 AC 497 ms
15,148 KB
testcase_14 AC 523 ms
15,236 KB
testcase_15 AC 471 ms
14,884 KB
testcase_16 AC 479 ms
14,940 KB
testcase_17 AC 496 ms
15,036 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 468 ms
14,924 KB
testcase_23 AC 343 ms
13,972 KB
testcase_24 AC 484 ms
15,084 KB
testcase_25 AC 442 ms
14,692 KB
testcase_26 AC 458 ms
14,804 KB
testcase_27 AC 1 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 1 ms
6,676 KB
testcase_38 AC 420 ms
15,260 KB
testcase_39 AC 467 ms
15,260 KB
testcase_40 AC 345 ms
13,972 KB
testcase_41 AC 547 ms
15,260 KB
testcase_42 AC 545 ms
15,260 KB
testcase_43 AC 542 ms
15,260 KB
testcase_44 AC 551 ms
15,260 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 + 1, 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 (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