結果

問題 No.14 最小公倍数ソート
ユーザー sugim48sugim48
提出日時 2014-12-20 05:23:35
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,673 ms / 5,000 ms
コード長 1,194 bytes
コンパイル時間 610 ms
コンパイル使用メモリ 89,348 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-09-02 19:47:02
合計ジャッジ時間 54,481 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 50 ms
4,368 KB
testcase_04 AC 4,673 ms
4,376 KB
testcase_05 AC 1,572 ms
4,368 KB
testcase_06 AC 1,836 ms
4,372 KB
testcase_07 AC 2,396 ms
4,372 KB
testcase_08 AC 3,154 ms
4,368 KB
testcase_09 AC 4,259 ms
4,368 KB
testcase_10 AC 4,182 ms
4,368 KB
testcase_11 AC 4,343 ms
4,372 KB
testcase_12 AC 4,469 ms
4,372 KB
testcase_13 AC 4,525 ms
4,368 KB
testcase_14 AC 4,395 ms
4,368 KB
testcase_15 AC 4,536 ms
4,372 KB
testcase_16 AC 1,684 ms
4,372 KB
testcase_17 AC 1,204 ms
4,368 KB
testcase_18 AC 536 ms
4,372 KB
testcase_19 AC 2,845 ms
4,368 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:49:41: warning: ‘_j’ may be used uninitialized in this function [-Wmaybe-uninitialized]
    if (x < _x || (x == _x && a[j] < a[_j])) {
                                         ^

ソースコード

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