結果
問題 | No.14 最小公倍数ソート |
ユーザー |
![]() |
提出日時 | 2014-12-20 05:20:40 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4,337 ms / 5,000 ms |
コード長 | 1,199 bytes |
コンパイル時間 | 1,007 ms |
コンパイル使用メモリ | 89,616 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-12 02:06:54 |
合計ジャッジ時間 | 48,531 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:49:62: warning: ‘_j’ may be used uninitialized in this function [-Wmaybe-uninitialized] 49 | if (x < _x || (x == _x && a[j] < a[_j])) { | ^
ソースコード
#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, _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'); }