/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Wrong Answer 1ms 532.0 KiB
#3 Accepted 1ms 484.0 KiB
#4 Wrong Answer 1ms 532.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'
int n;
vector<int> v;
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
const int N1 = 41, N2 = 41;
int dp[N1][N2];
int fun(int i, int c)
{
    if (i == n)
    {
        if (c == 0)
            return 0;
        else
            return 1;
    }
    if (c == 0)
        return 0;
    if (dp[i][c] != -1)
        return dp[i][c];
    int ans = fun(i + 1, c);
    ans = max(ans, gcd(v[i], fun(i + 1, c - 1)));
    return dp[i][c] = ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    v.resize(n);
    for (auto &x : v)
    {
        cin >> x;
    }
    memset(dp, -1, sizeof(dp));
    for (int k = 1; k <= n; k++)
        cout << fun(0, k) << " ";
    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 15:00:31
Judged At
2025-01-02 15:00:31
Judged By
Score
5
Total Time
1ms
Peak Memory
536.0 KiB