/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 840.0 KiB
#2 Accepted 3ms 1004.0 KiB
#3 Accepted 4ms 1020.0 KiB
#4 Accepted 3ms 1.012 MiB
#5 Accepted 3ms 840.0 KiB
#6 Accepted 3ms 840.0 KiB
#7 Accepted 4ms 1.008 MiB
#8 Accepted 221ms 1.004 MiB
#9 Time Exceeded ≥1026ms ≥796.0 KiB
#10 Time Exceeded ≥1078ms ≥1.195 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;
using vi = std::vector<int>;

int N, a[mxN];
std::vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
int idx[mxN];

std::vector<std::vector<std::map<vi, int>>> dp(mxN, std::vector<std::map<vi, int>> (mxN));
std::map<vi, int> g_ans;
std::vector<std::map<int,int>> tot(mxN);

int pw(int a, int b) {
    int res = 1;
    while (b--) res *= a;
    return res;
}

void calc(int at, vi cur) {
    if (at == N) {
        int g = 1;
        for (auto &p : primes) {
            int cnt = (cur[idx[p]] == 10 ? 0 : cur[idx[p]]);
            g *= pw(p,cnt);
        }
        g_ans[cur] = g;
        return;
    }
    calc(at+1, cur);
    for (auto &p : primes) {
        int v = idx[p];
        if (tot[at].find(p) != tot[at].end()) cur[v] = std::min(cur[v], tot[at][p]);
        else cur[v] = 0;
    }
    calc(at+1, cur);
}

// int fn(int at, int evc, vi pc) {
//     if (at == N) {
//         if (N%2==0) {
//             if (evc == (N-evc)) {
                
//             }
//             return 0;
//         }
//         if (evc+1 != (N-evc)) return 0;
//     }
//     int op1 = fn(at+1, evc, pc);
//     for (auto &p : primes) {
//         int v = idx[p];
//         if (tot[at].find(p) != tot[at].end()) pc[v] = std::min(pc[v], tot[at][p]);
//         else pc[v] = 0;
//     }
//     int op2 = fn(at+1, evc+1, pc);
//     return dp[at][evc][pc] = std::max(op1, op2);
// }

int fn(int at, int ec, int eg, int og) {
    // if (ec > N/2) return 0;
    if (at == N) {
        if (N&1) return (ec+1 == (N-ec)) ? eg+og : 0;
        return (ec == (N-ec)) ? eg+og : 0;
    }
    int op1 = fn(at+1, ec, eg, std::__gcd(og, a[at]));
    int op2 = fn(at+1, ec+1, std::__gcd(eg, a[at]), og);
    return std::max(op1, op2);
}

signed main() {
    // fastIO;
    int testCases=1;
    scanf("%d",&testCases);
    // std::cin>>testCases;
    
    // for (int i = 0; i < (int)primes.size(); i++) {
    //     idx[primes[i]] = i;
    // }
    
    for (int TC = 1; TC <= testCases; TC++) {
        scanf("%d",&N);
        for (int i = 0; i < N; i++) {
            scanf("%d",&a[i]);
        }
        
        printf("%d\n", fn(0,0,0,0));
        
        // for (int i = 0; i < N; i++) {
        //     int x = a[i];
        //     for (auto &p : primes) {
        //         if (x <= 1) break;
        //         if (x%p == 0) {
        //             int c = 0;
        //             while (x%p == 0) {
        //                 x /= p;
        //                 c++;
        //             }
        //             tot[i][p] = c;
        //         }
        //     }
        //     if (x > 1) tot[i][x] = 1;
        // }
        
        // std::vector<int> cur(25,10);
        // calc(0,cur);
        
        // for (auto &i : g_ans) {
        //     for (auto j : i.first) printf("%d ",j);
        //     printf(" : %d\n",i.second);
        // }
        
        // std::vector<int> dum(25,10);
        // printf("%d\n", fn(0,0,dum));
        // for (int i = 0; i < N; i++) {
        //     for (int j = 1; j <= 100; j++) dp[i][j].clear();
        // }
        
    }
    
    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-16 19:16:28
Judged At
2024-11-11 03:10:27
Judged By
Score
13
Total Time
≥1078ms
Peak Memory
≥1.195 MiB