/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 560.0 KiB
#2 Accepted 2ms 328.0 KiB
#3 Accepted 2ms 332.0 KiB
#4 Accepted 3ms 332.0 KiB
#5 Accepted 3ms 692.0 KiB
#6 Accepted 3ms 336.0 KiB
#7 Accepted 3ms 540.0 KiB
#8 Accepted 176ms 556.0 KiB
#9 Time Exceeded ≥1007ms ≥328.0 KiB
#10 Time Exceeded ≥1050ms ≥332.0 KiB
#11 Time Exceeded ≥1076ms ≥332.0 KiB
#12 Time Exceeded ≥1085ms ≥336.0 KiB
#13 Time Exceeded ≥1030ms ≥332.0 KiB
#14 Time Exceeded ≥1049ms ≥528.0 KiB
#15 Time Exceeded ≥1063ms ≥332.0 KiB
#16 Time Exceeded ≥1021ms ≥332.0 KiB
#17 Time Exceeded ≥1001ms ≥328.0 KiB
#18 Time Exceeded ≥1006ms ≥336.0 KiB
#19 Time Exceeded ≥1002ms ≥488.0 KiB

Code

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

int n, ans = 0;

void 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;
  }
  int a = gcd(gc, v[ind]);
  int b = gcd(gc2, v[ind]);
  max_gcd(ind + 1, v, a, gc2, cnt + 1);
  max_gcd(ind + 1, v, gc, b, cnt);
}

void solve()
{
  cin >> n;
  
  vector<int> v(n);
  for(int i = 0; i < n; i++) {
    cin >> v[i];
  }
  ans = 0;
  max_gcd(0, v, 0, 0, 0);
  cout << ans << "\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:04:50
Judged At
2024-10-03 13:16:24
Judged By
Score
13
Total Time
≥1085ms
Peak Memory
≥692.0 KiB