/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 836.0 KiB
#2 Accepted 2ms 1.062 MiB
#3 Accepted 6ms 1016.0 KiB
#4 Accepted 6ms 1.074 MiB
#5 Accepted 6ms 1.07 MiB
#6 Accepted 5ms 1.074 MiB
#7 Accepted 6ms 1.086 MiB
#8 Accepted 9ms 1.148 MiB
#9 Accepted 18ms 1.23 MiB
#10 Accepted 63ms 1.66 MiB
#11 Time Exceeded ≥1073ms ≥3.707 MiB
#12 Time Exceeded ≥1076ms ≥3.809 MiB

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 105;
const ll MOD = 1e9 + 7;

int n;
vector<vector<map<pair<int, int>, int>>> dp(N, vector<map<pair<int, int>, int>>(N));

int max_gcd(int ind, vector<int> &v, int gc, int gc2, int cnt) {
  if(ind == n) {
    if(cnt == (n + 1) / 2) {
      return gc + gc2;
    }
    return 0;
  }

  if (dp[ind][cnt].find({gc, gc2}) != dp[ind][cnt].end()) return dp[ind][cnt][{gc, gc2}];

  int take = max_gcd(ind + 1, v, gcd(gc, v[ind]), gc2, cnt + 1);
  int notTake = max_gcd(ind + 1, v, gc, gcd(gc2, v[ind]), cnt);

  return dp[ind][cnt][{gc, gc2}] = max(take, notTake);
}

void solve()
{
  cin >> n;
  
  vector<int> v(n);
  for(int i = 0; i < n; i++) {
    cin >> v[i];
  }
  
  cout << max_gcd(0, v, 0, 0, 0) << "\n";

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) dp[i][j].clear();
  }
}

int main()
{
  ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);

  int t;
  cin >> t;
  while(t--){
    solve();
  }
}

Information

Submit By
Type
Submission
Problem
P1076 Even Odd GCD (Easy Version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-18 15:29:47
Judged At
2024-11-11 03:07:42
Judged By
Score
25
Total Time
≥1076ms
Peak Memory
≥3.809 MiB