結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー norikamenorikame
提出日時 2021-11-05 22:39:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,065 bytes
コンパイル時間 2,000 ms
コンパイル使用メモリ 205,196 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-04-24 06:31:55
合計ジャッジ時間 6,447 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 326 ms
12,032 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

ll gcd(ll a, ll b) { return (b ? gcd(b, a%b) : a); }

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	unordered_map<ll, int> gvals;
	rep(i, n) {
		auto ngvals = gvals;
		for (auto pi : gvals) {
			ll gval = gcd(pi.first, a[i]);
			if (ngvals.find(gval) == ngvals.end()) ngvals[gval] = pi.second + 1;
			else ngvals[gval] = max(ngvals[gval], pi.second+1);
		}
		if (ngvals.find(a[i]) == ngvals.end()) ngvals[a[i]] = 1;
		else ngvals[a[i]] = max(ngvals[a[i]], 1);
		swap(gvals, ngvals);
	}
	vector<ll> mvals(n+1);
	for (auto pi : gvals) mvals[pi.second] = max(mvals[pi.second], pi.first);
	repr(i, n) mvals[i] = max(mvals[i], mvals[i+1]);
	rep3r(i, 1, n+1) cout << mvals[i] << endl;
	return 0;
}
0