結果

問題 No.14 最小公倍数ソート
ユーザー sugim48sugim48
提出日時 2014-12-20 05:29:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,804 ms / 5,000 ms
コード長 1,345 bytes
コンパイル時間 749 ms
コンパイル使用メモリ 90,884 KB
実行使用メモリ 394,352 KB
最終ジャッジ日時 2023-09-02 19:56:26
合計ジャッジ時間 37,968 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 282 ms
393,976 KB
testcase_01 AC 279 ms
393,924 KB
testcase_02 AC 280 ms
393,808 KB
testcase_03 AC 340 ms
393,748 KB
testcase_04 AC 2,741 ms
393,924 KB
testcase_05 AC 1,040 ms
393,968 KB
testcase_06 AC 1,256 ms
393,856 KB
testcase_07 AC 1,651 ms
393,968 KB
testcase_08 AC 1,983 ms
394,204 KB
testcase_09 AC 2,598 ms
393,804 KB
testcase_10 AC 2,570 ms
394,352 KB
testcase_11 AC 2,594 ms
394,348 KB
testcase_12 AC 2,676 ms
393,808 KB
testcase_13 AC 2,686 ms
394,352 KB
testcase_14 AC 2,708 ms
393,804 KB
testcase_15 AC 2,804 ms
394,352 KB
testcase_16 AC 1,555 ms
393,860 KB
testcase_17 AC 1,230 ms
393,984 KB
testcase_18 AC 762 ms
393,800 KB
testcase_19 AC 2,076 ms
394,040 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:51: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, vector< vector<int> >& memo) {
	if (b == 0) return a;
	else if (memo[a][b]) return memo[a][b];
	else return memo[a][b] = gcd(b, a % b, memo);
}

int main() {
	vector< vector<int> > memo(10001, vector<int>(10001));
	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], memo), 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