結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 294 ms
12,160 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 4 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 6 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];
	map<ll, int> gvals;
	rep(i, n) {
		for (auto itr=gvals.begin(); itr!=gvals.end(); ++itr) {
			ll gval = gcd(itr->first, a[i]);
			if (gvals.find(gval) == gvals.end()) gvals[gval] = itr->second + 1;
			else gvals[gval] = max(gvals[gval], itr->second+1);
		}
		if (gvals.find(a[i]) == gvals.end()) gvals[a[i]] = 1;
		else gvals[a[i]] = max(gvals[a[i]], 1);
	}
	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