結果
問題 | No.14 最小公倍数ソート |
ユーザー | lovablepleiad |
提出日時 | 2016-01-21 12:23:14 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 42 ms / 5,000 ms |
コード長 | 2,767 bytes |
コンパイル時間 | 812 ms |
コンパイル使用メモリ | 95,812 KB |
実行使用メモリ | 8,208 KB |
最終ジャッジ日時 | 2023-10-21 13:41:23 |
合計ジャッジ時間 | 2,180 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,348 KB |
testcase_01 | AC | 2 ms
4,348 KB |
testcase_02 | AC | 2 ms
4,348 KB |
testcase_03 | AC | 5 ms
4,928 KB |
testcase_04 | AC | 42 ms
8,208 KB |
testcase_05 | AC | 21 ms
6,572 KB |
testcase_06 | AC | 24 ms
6,848 KB |
testcase_07 | AC | 29 ms
7,232 KB |
testcase_08 | AC | 32 ms
7,588 KB |
testcase_09 | AC | 39 ms
8,048 KB |
testcase_10 | AC | 37 ms
8,028 KB |
testcase_11 | AC | 40 ms
8,128 KB |
testcase_12 | AC | 39 ms
8,132 KB |
testcase_13 | AC | 40 ms
8,140 KB |
testcase_14 | AC | 40 ms
8,116 KB |
testcase_15 | AC | 40 ms
8,180 KB |
testcase_16 | AC | 27 ms
7,076 KB |
testcase_17 | AC | 22 ms
6,700 KB |
testcase_18 | AC | 15 ms
6,028 KB |
testcase_19 | AC | 34 ms
7,672 KB |
ソースコード
#define _CRT_SECURE_NO_WARNINGS #include <string> #include <vector> #include <algorithm> #include <numeric> #include <set> #include <map> #include <queue> #include <iostream> #include <sstream> #include <cstdio> #include <cmath> #include <ctime> #include <cstring> #include <cctype> #include <cassert> #include <limits> #include <functional> #include <stack> #include <array> #include <fstream> #include <deque> #include <bitset> using namespace std; #define REP(i,n) for(int (i) = 0;(i) < (n) ; ++(i)) #define REPS(a,i,n) for(int (i) = (a) ; (i) < (n) ; ++(i)) #if defined(_MSC_VER)||__cplusplus > 199711L #define AUTO(r,v) auto r = (v) #else #define AUTO(r,v) typeof(v) r = (v) #endif #define ALL(c) (c).begin() , (c).end() #define EACH(it,c) for(AUTO(it,(c).begin());it != (c).end();) #define LL long long #define int LL #define inf ((int)1 << 54) #define mod 1000000007 #define QUICK_CIN ios::sync_with_stdio(false); cin.tie(0); #define lowb lower_bound #define upb upper_bound #define ZERO(c,n) memset(&c[0],0,sizeof(int)*n) #define ZERO2(c,n) memset(&c[0][0],0,sizeof(int)*n) #define debug_input fstream cin("input.txt");ofstream cout("output.txt"); #define pb(a) push_back(a) template<class T>void scan(vector<T>& a, int n, istream& cin) { T c; REP(i, n) { cin >> c; a.push_back(c); } } using vs = vector<string>; using vi = vector<int>; using pii = pair<int, int>; using psi = pair<string, int>; using vvi = vector<vi>; template<class T>bool valid(T x, T w) { return 0 <= x&&x < w; } int dx[4] = { 1, -1, 0, 0 }; int dy[4] = { 0, 0, 1, -1 }; //----------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------- int memo[10001]; set<int> s[10001]; vi aa[10001]; signed main() { QUICK_CIN; //debug_input; vi a; int n; cin >> n; REP(i, n) { int c; cin >> c; memo[c]++; a.push_back(c); } REP(i, n) { for (int x = 1; x*x <= a[i]; ++x) { if (a[i] % x == 0) { s[a[i] / x].insert(x); s[x].insert(a[i] / x); aa[a[i]].push_back(a[i] / x); aa[a[i]].push_back(x); } } } int now = a[0]; cout << now << " "; memo[now]--; while (true) { int min_co = inf; int min_t = inf; for (auto x : aa[now]) { auto it = s[x].begin(); while (it != s[x].end() && memo[x*(*it)] == 0) { it = s[x].erase(it); } if (it == s[x].end()) { continue; } if (now*(*it) < min_co || (now*(*it) == min_co && x*(*it) < min_t)) { min_co = now*(*it); min_t = x*(*it); } } if (min_t == inf) { break; } memo[min_t]--; cout << min_t << " "; now = min_t; } cout << endl; }