結果

問題 No.14 最小公倍数ソート
ユーザー kenken714kenken714
提出日時 2019-04-18 23:32:16
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,034 bytes
コンパイル時間 598 ms
コンパイル使用メモリ 82,088 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-23 16:27:18
合計ジャッジ時間 7,412 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 77 ms
4,348 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:42:63: warning: ‘man’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |                         if (ma > now or ((ma == now) and s[man] > s[j])) {
      |                                                          ~~~~~^

ソースコード

diff #

#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll n, s[11000];

ll gcd(ll a, ll b) {
	return (b == 0 ? a : gcd(b, a % b));
}

int main() {
	cin >> n;
	REP(i, n)cin >> s[i];
	REP(i, n - 1) {
		ll ma = INF, man;
		FOR(j, i + 1, n) {
			ll now = s[i] / gcd(s[i], s[j]) * s[j];
			if (ma > now or ((ma == now) and s[man] > s[j])) {
				ma = now;
				man = j;
			}
		}
		swap(s[i + 1], s[man]);
	}
	REP(i, n) {
		if (i != 0)cout << " ";
		cout << s[i];
	}
	cout << endl;
}



0