結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー norikamenorikame
提出日時 2021-11-12 10:05:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,028 bytes
コンパイル時間 2,196 ms
コンパイル使用メモリ 213,452 KB
実行使用メモリ 23,584 KB
最終ジャッジ日時 2024-05-03 15:57:43
合計ジャッジ時間 8,011 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 325 ms
13,884 KB
testcase_01 WA -
testcase_02 AC 2 ms
6,944 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 WA -
testcase_10 RE -
testcase_11 AC 2 ms
6,944 KB
testcase_12 WA -
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> avals;
	rep(i, n) avals[a[i]]++;
	int alen = avals.size();
	map<ll, int> gvals;
	for (auto pi : avals) {
		map<ll, int> adds;
		adds[pi.first] = pi.second;
		for (auto itr=gvals.begin(); itr!=gvals.end(); ++itr) adds[gcd(itr->first, pi.first)] += itr->second + pi.second;
		for (auto api : adds) gvals[api.first] += api.second;
	}
	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