/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 1.48 MiB
#2 Wrong Answer 3ms 1.574 MiB
#3 Wrong Answer 3ms 1.66 MiB

Code

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, N = 1e5 + 10, mx  = 0;
    cin >> n;
    vector<int> a(n + 1), vis(N), p(N), ans(N, 1);
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        vis[a[i]]++;
        mx = max(mx, a[i]);
    }
    for (int i = 2; i <= mx; i++){
        if (p[i] != 1 && vis[i]){
            vector<int> tmp;
            for (int j = i; j <= mx; j += i){
                p[j] = 1;
                int x = vis[j];
                if (vis[j]){
                    while (x){
                        tmp.push_back(j);
                        x--;
                    }
                    
                }
            }
            int x  = tmp.size();
            for (int k = 0; k < x; k++){
                ans[k + 1] = max(ans[k + 1], tmp[x - k - 1]);
            }
        }
    }
    if (mx == 0){
        for (int i = 1; i <= n; i++){
            cout << mx << ' ';
        }
        return 0;
    }
    if (mx == 1){
        for (int i = 1; i <= n; i++){
            cout << mx << ' ';
        }
        return 0;
    }
    for (int i = 1; i <= n; i++){
        cout << ans[i] << ' ';
    }
    cout << endl;
}

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 16:13:22
Judged At
2025-01-02 16:13:22
Judged By
Score
0
Total Time
3ms
Peak Memory
1.66 MiB