結果

問題 No.14 最小公倍数ソート
ユーザー kenken714kenken714
提出日時 2019-04-18 23:21:28
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,036 bytes
コンパイル時間 941 ms
コンパイル使用メモリ 89,420 KB
実行使用メモリ 8,172 KB
最終ジャッジ日時 2023-10-23 16:26:43
合計ジャッジ時間 7,358 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll n, s[11000];

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
int main() {
	cin.tie(0);
	cin >> n;
	REP(i, n)cin >> s[i];
	REP(i, n) {
		vector<P>now;
		FOR(j, i + 1, n)now.push_back(P(lcm(s[i], s[j]), s[j]));
		sort(ALL(now));
		REP(j, now.size())s[i + j + 1] = now[j].second;
	}
	REP(i, n) {
		if (i != 0)cout << " ";
		cout << s[i];
	}
	cout << endl;
}



0