/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 87ms 99.887 MiB
#2 Accepted 128ms 100.145 MiB
#3 Accepted 592ms 100.426 MiB
#4 Accepted 613ms 100.465 MiB
#5 Accepted 591ms 100.492 MiB
#6 Accepted 595ms 100.57 MiB
#7 Accepted 594ms 100.672 MiB
#8 Accepted 609ms 102.199 MiB
#9 Accepted 617ms 104.703 MiB
#10 Accepted 637ms 111.602 MiB
#11 Accepted 924ms 142.703 MiB
#12 Accepted 924ms 177.73 MiB
#13 Accepted 686ms 163.043 MiB
#14 Accepted 711ms 171.055 MiB
#15 Accepted 677ms 172.129 MiB
#16 Accepted 696ms 139.867 MiB
#17 Accepted 730ms 171.094 MiB
#18 Accepted 784ms 151.766 MiB
#19 Accepted 782ms 147.992 MiB

Code

// I AM A MUSLIM

#include "bits/stdc++.h"

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#define fastIO std::ios::sync_with_stdio(0);std::cin.tie(0)
#define ll long long int
#define flush fflush(stdout)
#define bl printf("\n")
#define yn(a, b) printf("%s\n", a >= b ? "Yes":"No")
// #define int ll

using pii = std::pair<int,int>;

const int MOD = 1000000007;
// const int MOD = 998244353;
const int mxN = 101;

int N, a[mxN], dp[mxN][mxN][mxN][mxN];
bool used[mxN][mxN][mxN][mxN];

int fn(int at, int evC, int evG, int odG) {
    if (at == N) {
        if (N&1) return ((evC+1) == (N-evC)) ? evG+odG : -100100;
        return (evC == (N-evC)) ? evG+odG : -100100;
    }
    if (used[at][evC][evG][odG]) return dp[at][evC][evG][odG];
    int op1 = fn(at+1, evC+1, std::__gcd(evG,a[at]), odG);
    int op2 = fn(at+1, evC, evG, std::__gcd(odG,a[at]));
    used[at][evC][evG][odG] = 1;
    return dp[at][evC][evG][odG] = std::max(op1, op2);
}

signed main() {
    // fastIO;
    int testCases=1;
    scanf("%d",&testCases);
    // std::cin>>testCases;
    
    for (int TC = 1; TC <= testCases; TC++) {
        scanf("%d",&N);
        for (int i = 0; i < N; i++) {
            scanf("%d",&a[i]);
        }
        memset(used,0,sizeof(used));
        printf("%d\n", fn(0,0,0,0));
        
    }
    
    return 0;
}

/*

*/

Information

Submit By
Type
Submission
Problem
P1076 Even Odd GCD (Easy Version)
Contest
Bangladesh 2.0
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-16 16:15:48
Judged At
2024-10-03 13:27:51
Judged By
Score
100
Total Time
924ms
Peak Memory
177.73 MiB