/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 320.0 KiB
#2 Wrong Answer 3ms 324.0 KiB
#3 Wrong Answer 3ms 324.0 KiB

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;

void solve() {
    ll n;
    cin >> n;
    vector<ll> v(n);
    for (int i = 0; i < n; i++) {
        ll x; cin >> x;
        v[i] = x;
    }
    
    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>> (((n >> 1) + 2), vector<int> ((n >> 1) + 1, -1)));
    auto rec = [&](int i, int odd, int even, ll gcd1, ll gcd2, auto&& self) -> int {
        if(i == n) return gcd1 + gcd2;
        int &mx = dp[i][odd][even];
        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 06:03:54
Judged At
2024-11-11 03:05:50
Judged By
Score
1
Total Time
3ms
Peak Memory
324.0 KiB