/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 2.52 MiB
#2 Wrong Answer 4ms 2.469 MiB
#3 Wrong Answer 9ms 2.574 MiB

Code

#include<bits/stdc++.h>
#define endl        '\n'
#define F           first
#define S           second
#define pb          push_back
#define yes         cout<<"YES\n"
#define no          cout<<"NO\n"
#define all(x)      x.begin(),x.end()
#define allr(x)     x.rbegin(),x.rend()
#define error1(x)   cerr<<#x<<" = "<<(x)<<endl
#define error2(a,b) cerr<<"("<<#a<<", "<<#b<<") = ("<<(a)<<", "<<(b)<<")\n";
#define coutall(v)  for(auto &it: v) cout << it << " "; cout << endl;
using namespace std;
using ll = long long;
using ld = long double;

int dp[52][101][101];

void solve() {
    ll n;
    cin >> n;
    vector<ll> v(n);
    for (int i = 0; i < n; i++) {
        ll x; cin >> x;
        v[i] = x;
    }
    
    memset(dp, -1, sizeof dp);

    auto rec = [&](int i, int odd, int even, ll gcd1, ll gcd2, auto&& self) -> int {
        if(i == n) return gcd1 + gcd2;
        int &mx = dp[odd][gcd1][gcd2];
        if(mx != -1) return mx;
        mx = 0;
        if(odd > 0) {
            if(gcd1 == -1) mx = max(mx, self(i + 1, odd - 1, even, v[i], gcd2, self));
            else mx = max(mx, self(i + 1, odd - 1, even, __gcd(gcd1, v[i]), gcd2, self));
        }
        if(even > 0) {
            if(gcd2 == -1) mx = max(mx, self(i + 1, odd, even - 1, gcd1, v[i], self));
            else mx = max(mx, self(i + 1, odd, even - 1, gcd1, __gcd(v[i], gcd2), self));
        }
        return mx;
    };

    cout << rec(0, (n + 1) >> 1, n >> 1, -1, -1, rec) << endl;
    return;
}

signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int tc = 1;
    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case " << t << ": ";
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1076 Even Odd GCD (Easy Version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-23 09:28:26
Judged At
2024-11-11 03:05:47
Judged By
Score
1
Total Time
9ms
Peak Memory
2.574 MiB