/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 320.0 KiB
#2 Wrong Answer 14ms 532.0 KiB
#3 Wrong Answer 13ms 560.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:09:40
Judged At
2025-01-02 15:09:40
Judged By
Score
0
Total Time
14ms
Peak Memory
560.0 KiB