結果

問題 No.14 最小公倍数ソート
ユーザー yogi_cg
提出日時 2020-03-29 17:41:25
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,419 bytes
コンパイル時間 1,890 ms
コンパイル使用メモリ 180,864 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-01-02 15:35:03
合計ジャッジ時間 3,338 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    vi a(N); REP(i, N) cin >> a[i];
    vi tmp = a;
    sort(ALL(tmp));
    vb exist(10001, false);
    map<int, int> m;
    REP(i, N)
    {
        int x = tmp[i];
        for(int j = 2; j < tmp[i]; j++)
        {
            if(exist[j] && tmp[i] % j == 0) tmp[i] /= j;
        }
        m[x] = tmp[i];
        exist[tmp[i]] = true;
    }
    /*
    REP(i, N) cout << tmp[i] << " ";
    cout << endl;
    */
    vpi p(N);
    REP(i, N)
    {
        p[i] = mp(m[a[i]], a[i]);
    }
    sort(p.begin()+1, p.end());
    REP(i, N) cout << p[i].se << " ";
    cout << endl;
}
0