結果

問題 No.14 最小公倍数ソート
ユーザー simezi_tansimezi_tan
提出日時 2015-07-21 21:35:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3,107 ms / 5,000 ms
コード長 1,139 bytes
コンパイル時間 2,555 ms
コンパイル使用メモリ 155,184 KB
実行使用メモリ 101,736 KB
最終ジャッジ日時 2023-09-22 21:01:35
合計ジャッジ時間 40,743 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 406 ms
101,364 KB
testcase_01 AC 430 ms
101,488 KB
testcase_02 AC 406 ms
101,412 KB
testcase_03 AC 452 ms
101,332 KB
testcase_04 AC 3,107 ms
101,528 KB
testcase_05 AC 1,260 ms
101,648 KB
testcase_06 AC 1,390 ms
101,464 KB
testcase_07 AC 1,735 ms
101,652 KB
testcase_08 AC 2,123 ms
101,484 KB
testcase_09 AC 2,866 ms
101,468 KB
testcase_10 AC 2,794 ms
101,600 KB
testcase_11 AC 2,901 ms
101,736 KB
testcase_12 AC 2,974 ms
101,652 KB
testcase_13 AC 3,022 ms
101,524 KB
testcase_14 AC 2,959 ms
101,648 KB
testcase_15 AC 3,023 ms
101,576 KB
testcase_16 AC 1,397 ms
101,500 KB
testcase_17 AC 1,137 ms
101,636 KB
testcase_18 AC 740 ms
101,440 KB
testcase_19 AC 2,041 ms
101,452 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<ll> v;
		for(int j = i + 1; j < n; j++) v.pb(ll(a[i] / g[max(a[i], a[j])][min(a[i], a[j])] * a[j]) << 32 | 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] & (1 << 29) - 1;
	}
	
	rep(i, n) printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');
	
	return 0;
}
0