結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー HIcoderHIcoder
提出日時 2023-07-17 19:09:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,598 bytes
コンパイル時間 1,407 ms
コンパイル使用メモリ 125,968 KB
実行使用メモリ 20,824 KB
最終ジャッジ日時 2023-10-18 00:34:42
合計ジャッジ時間 8,761 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 365 ms
20,416 KB
testcase_01 AC 4 ms
11,036 KB
testcase_02 AC 49 ms
19,084 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 5 ms
11,036 KB
testcase_09 AC 33 ms
16,776 KB
testcase_10 WA -
testcase_11 AC 4 ms
11,036 KB
testcase_12 AC 4 ms
11,036 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 325 ms
14,272 KB
testcase_19 AC 383 ms
20,668 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 350 ms
18,360 KB
testcase_23 AC 286 ms
12,688 KB
testcase_24 AC 331 ms
20,416 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);
        ansg[sum[g]]=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(1LL<<60,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以上で考えた際に最大のg
        auto it=lower_bound(t.begin(),t.end(),make_pair(c,0LL));
        //it--;

        ans=it->second;

        


        cout<<ans<<endl;
    


    }

    






}
0