結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー HIcoderHIcoder
提出日時 2023-07-17 19:21:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 386 ms / 2,000 ms
コード長 1,820 bytes
コンパイル時間 974 ms
コンパイル使用メモリ 111,108 KB
実行使用メモリ 21,984 KB
最終ジャッジ日時 2023-10-18 00:34:51
合計ジャッジ時間 8,444 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 363 ms
21,984 KB
testcase_01 AC 47 ms
19,080 KB
testcase_02 AC 46 ms
19,080 KB
testcase_03 AC 47 ms
19,080 KB
testcase_04 AC 46 ms
19,080 KB
testcase_05 AC 46 ms
19,080 KB
testcase_06 AC 47 ms
19,080 KB
testcase_07 AC 47 ms
19,080 KB
testcase_08 AC 46 ms
19,080 KB
testcase_09 AC 47 ms
19,080 KB
testcase_10 AC 48 ms
19,080 KB
testcase_11 AC 45 ms
19,080 KB
testcase_12 AC 46 ms
19,080 KB
testcase_13 AC 386 ms
21,984 KB
testcase_14 AC 376 ms
21,984 KB
testcase_15 AC 383 ms
21,984 KB
testcase_16 AC 378 ms
21,984 KB
testcase_17 AC 374 ms
21,984 KB
testcase_18 AC 353 ms
21,984 KB
testcase_19 AC 361 ms
21,984 KB
testcase_20 AC 345 ms
21,984 KB
testcase_21 AC 351 ms
21,984 KB
testcase_22 AC 361 ms
21,984 KB
testcase_23 AC 326 ms
21,984 KB
testcase_24 AC 328 ms
21,984 KB
testcase_25 AC 359 ms
21,984 KB
権限があれば一括ダウンロードができます

ソースコード

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の倍数
        }
    }

    vector<ll> ans(N+1,0);

    for(int i=1;i<=MAXA;i++){
        ans[max(N-sum[i],0LL)]=i;
        // ans[全体N - gの倍数の個数]=i
        
    }

    for(int i=1;i<=N;i++){
        ans[i]=max(ans[i],ans[i-1]);
    }

    for(int i=0;i<N;i++){
        cout<<ans[i]<<endl;
    }




    /*
    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 K=0;K<N;K++){

        ll ans=0;

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

        ll c=N-K;

        //個数がc以上で考えた際に最大のg
        auto it=upper_bound(t.begin(),t.end(),make_pair(c,1LL<<30));
        it--;

        ans=it->second;

        


        cout<<ans<<endl;
    


    }

    */
    






}
0