結果

問題 No.14 最小公倍数ソート
ユーザー sugim48sugim48
提出日時 2014-12-20 05:19:30
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,203 bytes
コンパイル時間 2,761 ms
コンパイル使用メモリ 88,204 KB
実行使用メモリ 4,496 KB
最終ジャッジ日時 2023-09-02 19:41:08
合計ジャッジ時間 64,267 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<int, ll> i_ll;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int gcd(int a, int b) {
	if (b == 0) return abs(a);
	else return gcd(b, a % b);
}

int main() {
	int N; cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++)
		cin >> a[i];
	for (int i = 0; i + 1 < N; i++) {
		int _j = i + 1;
		for (int j = i + 1; j < N; j++) {
			int d = gcd(a[i], a[j]), x = a[j] / d;
			int _d = gcd(a[i], a[_j]), _x = a[_j] / _d;
			if (x < _x || (x == _x && a[j] < a[_j]))
				_j = j;
		}
		swap(a[i + 1], a[_j]);
	}
	for (int i = 0; i < N; i++)
		cout << a[i] << (i + 1 < N ? ' ' : '\n');
}
0