結果

問題 No.14 最小公倍数ソート
ユーザー simezi_tansimezi_tan
提出日時 2015-07-21 21:31:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3,478 ms / 5,000 ms
コード長 1,123 bytes
コンパイル時間 1,272 ms
コンパイル使用メモリ 157,088 KB
実行使用メモリ 101,712 KB
最終ジャッジ日時 2023-09-22 21:00:37
合計ジャッジ時間 43,910 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 436 ms
101,292 KB
testcase_01 AC 428 ms
101,344 KB
testcase_02 AC 425 ms
101,276 KB
testcase_03 AC 454 ms
101,320 KB
testcase_04 AC 3,478 ms
101,428 KB
testcase_05 AC 1,395 ms
101,536 KB
testcase_06 AC 1,577 ms
101,416 KB
testcase_07 AC 1,919 ms
101,448 KB
testcase_08 AC 2,385 ms
101,696 KB
testcase_09 AC 3,163 ms
101,456 KB
testcase_10 AC 3,122 ms
101,520 KB
testcase_11 AC 3,237 ms
101,436 KB
testcase_12 AC 3,316 ms
101,712 KB
testcase_13 AC 3,348 ms
101,432 KB
testcase_14 AC 3,278 ms
101,456 KB
testcase_15 AC 3,349 ms
101,516 KB
testcase_16 AC 1,528 ms
101,532 KB
testcase_17 AC 1,198 ms
101,536 KB
testcase_18 AC 769 ms
101,532 KB
testcase_19 AC 2,231 ms
101,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, a[10000];
vector<vector<short>> g;

int main(){
	g.resize(10001);
	for(int i = 1; i <= 10000; i++){
		g[i].resize(i + 1);
		for(int j = 1; j < i; j++) g[i][j] = g[max(i - j, j)][min(i - j, j)];
		g[i][i] = i;
	}
	
	cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n){
		vector<pi> v;
		for(int j = i + 1; j < n; j++) v.pb(pi(a[i] / g[max(a[i], a[j])][min(a[i], a[j])] * a[j], a[j]));
		#if 0
		rep(j, v.size()) cerr<<v[j].first<<(j==v.size()-1?"\n":" ");
		rep(j, v.size()) cerr<<v[j].second<<(j==v.size()-1?"\n":" ");
		cerr<<endl;
		#endif
		sort(all(v));
		rep(j, v.size()) a[i + j + 1] = v[j].second;
	}
	
	rep(i, n) printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');
	
	return 0;
}
0