結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー HIcoderHIcoder
提出日時 2023-07-17 19:05:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,564 bytes
コンパイル時間 1,876 ms
コンパイル使用メモリ 126,608 KB
実行使用メモリ 20,756 KB
最終ジャッジ日時 2023-10-18 00:34:33
合計ジャッジ時間 11,697 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 373 ms
20,432 KB
testcase_01 AC 4 ms
11,052 KB
testcase_02 AC 52 ms
19,100 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 4 ms
11,052 KB
testcase_09 AC 37 ms
16,792 KB
testcase_10 WA -
testcase_11 AC 5 ms
11,052 KB
testcase_12 AC 5 ms
11,052 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 335 ms
14,288 KB
testcase_19 AC 409 ms
20,684 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 353 ms
18,376 KB
testcase_23 AC 288 ms
12,704 KB
testcase_24 AC 335 ms
20,432 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set> 
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include <unordered_set>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=1e9+7;


int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    const int MAXA=1000000;
    vector<ll> cnt(MAXA+10);
    ll maxA=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        maxA=max(maxA,A[i]);
        cnt[A[i]]++;
    }

    vector<ll> sum(maxA+1);
    for(int g=1;g<=maxA;g++){
        for(int j=g;j<=maxA;j+=g){
            sum[g]+=cnt[j];//jはgの倍数
        }
    }

    map<ll,ll> ansg;
    for(int g=1;g<=maxA;g++){
        //sumが同じならできるだけ大きいgがいい
        ansg[sum[g]]=max(ansg[sum[g]],1LL*g);
    }

    vector<pair<ll,ll>> t;//[数,その値]
    for(auto [num,g]:ansg){
        t.emplace_back(num,g);
    }
    //t.emplace_back(make_pair(0LL,1LL<<30));//番兵
    t.emplace_back(make_pair(1<<30,1LL));

    //numが小さい順にソート
    sort(t.begin(),t.end());

    /*
    for(int j=0;j<=maxA;j++){
        cout<<"sum["<<j<<"]="<<sum[j]<<endl;
    }
    */

    for(int K=0;K<N;K++){

        ll ans=0;

        //cout<<"N-K="<<N-K<<endl;

        ll c=N-K;

        //個数がc以上で最小の値
        auto it=lower_bound(t.begin(),t.end(),make_pair(c,-(1LL<<30)));
        //it--;

        ans=it->second;

        


        cout<<ans<<endl;
    


    }

    






}
0