/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Runtime Error terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size() 1ms 532.0 KiB
#2 Runtime Error terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size() 1ms 532.0 KiB

Code

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

#define ll long long

int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int dx2[] = {1, -1, 0, 0, -1, 1, -1, 1};
int dy2[] = {0, 0, 1, -1, 1, 1, -1, -1};
int knightX[] = {-2, -2, 2, 2, 1, 1, -1, -1};
int knightY[] = {-1, 1, -1, 1, -2, 2, -2, 2};

const ll INF = 0x3f3f3f3f;
const int N = 1e5, K = 105;
const ll MOD = 1e9 + 7;

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vector<int> v(n);
        for(int i = 0; i < n; i++) {
            cin >> v[i];
        }
        vector<vector<ll>> dp(n+1, vector<ll>(N + 1, 0));
        for(auto &i : v){
            for(int j = n; j >= 1; j--){
                if(j == 1){
                    dp[1][i]++;
                }
                else{
                    for(int k = 1; k <= N; k++){
                        if(dp[j - 1][k] > 0){
                            dp[j][gcd(k, i)] += dp[j - 1][k];
                        }
                    }
                }
            }
        }

        for(int i = 1; i <= n; i++){
            int ans = 1;
            for(int j = N; j >=1; j--){
                if(dp[i][j] > 0){
                    ans = j;
                    break;
                }
            }
            cout << ans << (i == 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:09
Judged At
2025-01-02 14:58:09
Judged By
Score
0
Total Time
1ms
Peak Memory
532.0 KiB