/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 5ms 4.258 MiB
#2 Wrong Answer 206ms 32.668 MiB
#3 Wrong Answer 203ms 32.754 MiB

Code

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    const int MAXG = 100000;
    vector<vector<long long>> dp(N+1, vector<long long>(MAXG + 1, 0));

    for(auto x : A){
        for(int k = N; k >= 1; k--){
            if(k == 1){
                dp[1][x] +=1;
            }
            else{
                for(int g = 1; g <= MAXG; g++){
                    if(dp[k-1][g] > 0){
                        int newG = gcd(g, x);
                        dp[k][newG] += dp[k-1][g];
                    }
                }
            }
        }
    }

    for(int k = 1; k <= N; k++){
        int maxG = 1; // Minimum possible GCD
        for(int g = MAXG; g >=1; g--){
            if(dp[k][g] > 0){
                maxG = g;
                break;
            }
        }
        cout << maxG << (k == N ? '\n' : ' ');
    }

    return 0;
}

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 14:58:47
Judged At
2025-01-02 14:58:47
Judged By
Score
0
Total Time
206ms
Peak Memory
32.754 MiB