結果

問題 No.1730 GCD on Blackboard in yukicoder
ユーザー SamShawCraftSamShawCraft
提出日時 2022-01-15 17:31:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 774 ms / 2,000 ms
コード長 1,038 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 74,496 KB
実行使用メモリ 17,056 KB
最終ジャッジ日時 2024-04-25 17:56:28
合計ジャッジ時間 6,912 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
8,184 KB
testcase_01 AC 5 ms
7,252 KB
testcase_02 AC 5 ms
7,312 KB
testcase_03 AC 4 ms
7,312 KB
testcase_04 AC 5 ms
7,312 KB
testcase_05 AC 5 ms
7,308 KB
testcase_06 AC 4 ms
7,300 KB
testcase_07 AC 5 ms
7,156 KB
testcase_08 AC 4 ms
7,180 KB
testcase_09 AC 5 ms
7,248 KB
testcase_10 AC 5 ms
7,096 KB
testcase_11 AC 5 ms
7,236 KB
testcase_12 AC 4 ms
7,312 KB
testcase_13 AC 558 ms
16,368 KB
testcase_14 AC 564 ms
16,416 KB
testcase_15 AC 566 ms
16,360 KB
testcase_16 AC 559 ms
16,396 KB
testcase_17 AC 566 ms
16,288 KB
testcase_18 AC 298 ms
17,056 KB
testcase_19 AC 774 ms
16,984 KB
testcase_20 AC 44 ms
8,012 KB
testcase_21 AC 45 ms
8,168 KB
testcase_22 AC 44 ms
7,976 KB
testcase_23 AC 37 ms
7,912 KB
testcase_24 AC 38 ms
7,916 KB
testcase_25 AC 526 ms
16,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <vector>
#define qaq inline
const int sz=1e6+19;
int n,arr[sz];
std::unordered_map<int,int> cnts;
std::vector<int> solve(){
    std::vector<int> divCnt(1e6+1,0),divisors;
    for(auto [ele,ct]:cnts){
        divisors.clear();
        for(int cx=1;cx*cx<=ele;++cx){
            if(ele%cx==0){
                divisors.push_back(cx);
                if(cx*cx!=ele)
                    divisors.push_back(ele/cx);
            }
        }
        for(auto cx:divisors)
            divCnt[cx]+=ct;
    }
    std::vector<int> ans(n,0);
    for(int cx=1;cx<=1e6;++cx){
        if(divCnt[cx]!=0)
            ans[n-divCnt[cx]]=std::max(ans[n-divCnt[cx]],cx);
    }
    for(int cx=1;cx<n;++cx)
        ans[cx]=std::max(ans[cx],ans[cx-1]);
    return ans;
}
int main(){
    scanf("%d",&n);
    for(int cx=0,u;cx<n;++cx){
        scanf("%d",&u);
        cnts[u]++;
    }
    auto ans=solve();
    for(auto cx:ans)
        printf("%d\n",cx);
    return 0;
}
0