結果

問題 No.14 最小公倍数ソート
ユーザー mayoko_mayoko_
提出日時 2015-11-06 14:15:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,647 bytes
コンパイル時間 715 ms
コンパイル使用メモリ 88,864 KB
実行使用メモリ 9,328 KB
最終ジャッジ日時 2023-10-11 14:20:44
合計ジャッジ時間 2,374 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 10011;
int a[MAXN];
set<pii> S[MAXN];
vector<int> divs[MAXN];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        for (int j = 1; j*j <= a[i]; j++) {
            if (a[i]%j == 0) {
                divs[i].push_back(j);
                S[j].insert(pii(a[i], i));
                if (j*j != a[i]) {
                    divs[i].push_back(a[i]/j);
                    S[a[i]/j].insert(pii(a[i], i));
                }
            }
        }
    }
    int index = 0;
    for (int i = 0; i < N; i++) {
        cout << a[index] << " ";
        int mini = 1<<30;
        int id = 0;
        for (int div : divs[index]) {
            S[div].erase(pii(a[index], index));
            if (S[div].empty()) continue;
            pii p = *S[div].begin();
            int tmp = p.first/div * a[index];
            if (tmp < mini) {
                mini = tmp;
                id = p.second;
            }
        }
        index = id;
    }
    cout << endl;
    return 0;
}
0