結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー norikamenorikame
提出日時 2021-11-12 17:37:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,033 ms / 2,000 ms
コード長 952 bytes
コンパイル時間 2,368 ms
コンパイル使用メモリ 203,016 KB
実行使用メモリ 18,292 KB
最終ジャッジ日時 2024-04-25 17:50:20
合計ジャッジ時間 13,176 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 338 ms
8,664 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 6 ms
7,388 KB
testcase_03 AC 7 ms
7,248 KB
testcase_04 AC 7 ms
7,228 KB
testcase_05 AC 7 ms
7,324 KB
testcase_06 AC 7 ms
7,168 KB
testcase_07 AC 7 ms
7,240 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 6 ms
6,944 KB
testcase_10 AC 6 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 892 ms
17,140 KB
testcase_14 AC 889 ms
17,204 KB
testcase_15 AC 897 ms
17,416 KB
testcase_16 AC 892 ms
17,236 KB
testcase_17 AC 897 ms
17,380 KB
testcase_18 AC 592 ms
15,104 KB
testcase_19 AC 1,033 ms
18,292 KB
testcase_20 AC 330 ms
7,568 KB
testcase_21 AC 330 ms
7,552 KB
testcase_22 AC 339 ms
7,572 KB
testcase_23 AC 296 ms
6,944 KB
testcase_24 AC 298 ms
8,816 KB
testcase_25 AC 799 ms
18,108 KB
権限があれば一括ダウンロードができます

ソースコード

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<int> a(n);
	rep(i, n) cin >> a[i];
	map<int, int> avals;
	rep(i, n) avals[a[i]]++;
	int mval = avals.rbegin()->first;
	vector<int> gcnt(mval+1);
	for (auto pi : avals) {
		for (int i=1; i*i<=pi.first; ++i) if (pi.first%i == 0) {
			gcnt[i] += pi.second;
			if (i != pi.first/i) gcnt[pi.first/i] += pi.second;
		}
	}
	vector<int> mvals(n+1);
	rep3(i, 1, mval+1) mvals[gcnt[i]] = max(mvals[gcnt[i]], i);
	repr(i, n) mvals[i] = max(mvals[i], mvals[i+1]);
	rep3r(i, 1, n+1) cout << mvals[i] << endl;
	return 0;
}
0