/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 532.0 KiB
#2 Accepted 14ms 532.0 KiB
#3 Accepted 13ms 560.0 KiB
#4 Accepted 15ms 560.0 KiB
#5 Accepted 15ms 532.0 KiB
#6 Accepted 15ms 560.0 KiB
#7 Accepted 15ms 532.0 KiB
#8 Accepted 15ms 504.0 KiB
#9 Accepted 13ms 556.0 KiB
#10 Accepted 15ms 532.0 KiB
#11 Accepted 19ms 532.0 KiB
#12 Accepted 19ms 532.0 KiB
#13 Accepted 7ms 564.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define endl "\n"
vector<int> takeVectorInput(int n){
    vector<int>v(n);
    for(auto &ele:v)cin>>ele;


//     vector<int>v(n+1);
//    for(int i=1;i<=n;++i) {
//     cin>>v[i];
//    }
    return v;
}
void solve(){
    int n;
    cin>>n;
    auto v=takeVectorInput(n);
    vector<int> ans(n+1,1);
    for(int i=1;i<=1e5;++i){
        int cnt=0;
        for(int j=0;j<n;++j){
            if(v[j]%i==0)cnt++;
        }
        ans[cnt]=max(ans[cnt],i);
    }
   int gc=0;
   for(auto &ele:v)gc=__gcd(gc,ele);
   ans[n]=max(ans[n],gc);
    for(int i=n-1;i>=1;--i)ans[i]=max(ans[i+1],ans[i]);
    int maxi=*max_element(v.begin(),v.end());
    int cnt=count(v.begin(),v.end(),0);
    if(cnt>0){
        for(int i=1;i<=cnt+(cnt<n?1:0);++i)cout<<maxi<<" ";
        for(int i=cnt+2;i<=n;++i)cout<<ans[i]<<" ";
        cout<<endl;
        return;
    }
    for(int i=1;i<=n;++i)cout<<ans[i]<<" ";
    cout<<endl;
}
signed main(){
    fast
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
}

Information

Submit By
Type
Submission
Problem
P1151 Max gcd group
Contest
Happy New Year 2025
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-02 15:13:49
Judged At
2025-01-02 15:13:49
Judged By
Score
100
Total Time
19ms
Peak Memory
564.0 KiB