/ SeriousOJ /

Record Detail

Memory Exceeded


  
# Status Time Cost Memory Cost
#1 Memory Exceeded ≥1112ms ≥256.016 MiB
#2 Memory Exceeded ≥1084ms ≥256.016 MiB
#3 Memory Exceeded ≥1066ms ≥256.016 MiB
#4 Memory Exceeded ≥1089ms ≥256.016 MiB
#5 Memory Exceeded ≥1053ms ≥256.016 MiB
#6 Memory Exceeded ≥1080ms ≥256.016 MiB
#7 Memory Exceeded ≥1104ms ≥256.016 MiB
#8 Memory Exceeded ≥1094ms ≥256.016 MiB
#9 Memory Exceeded ≥1077ms ≥256.016 MiB
#10 Memory Exceeded ≥1094ms ≥256.016 MiB
#11 Memory Exceeded ≥1075ms ≥256.016 MiB
#12 Memory Exceeded ≥1061ms ≥256.016 MiB
#13 Memory Exceeded ≥1074ms ≥256.016 MiB
#14 Memory Exceeded ≥1078ms ≥256.016 MiB
#15 Memory Exceeded ≥1103ms ≥256.016 MiB
#16 Memory Exceeded ≥1063ms ≥256.016 MiB
#17 Memory Exceeded ≥1083ms ≥256.016 MiB
#18 Memory Exceeded ≥1088ms ≥256.016 MiB
#19 Memory Exceeded ≥1103ms ≥256.016 MiB

Code

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

int n, ans = 0;
int dp[N][N][N][N];

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

  if(dp[ind][gc][gc2][cnt] != -1) return dp[ind][gc][gc2][cnt];

  return dp[ind][gc][gc2][cnt] = max(max_gcd(ind + 1, v, gcd(gc, v[ind]), gc2, cnt + 1),
  max_gcd(ind + 1, v, gc, gcd(gc2, v[ind]), cnt));
}

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

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:15:19
Judged At
2024-10-03 13:16:23
Judged By
Score
0
Total Time
≥1112ms
Peak Memory
≥256.016 MiB