/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 320.0 KiB
#2 Accepted 2ms 320.0 KiB
#3 Wrong Answer 3ms 320.0 KiB
#4 Accepted 3ms 556.0 KiB
#5 Accepted 3ms 328.0 KiB
#6 Accepted 3ms 320.0 KiB
#7 Accepted 3ms 324.0 KiB
#8 Accepted 3ms 320.0 KiB
#9 Accepted 4ms 324.0 KiB
#10 Accepted 6ms 532.0 KiB
#11 Accepted 15ms 324.0 KiB
#12 Wrong Answer 16ms 568.0 KiB

Code

#include <bits/stdc++.h>
#define ll long long
#define endll '\n';
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;


const int mod = 1e9 + 7, N = 1e6;
 
void solve()
{
 int n; cin >> n;
 int ar[n + 3];
 for(int i = 1; i <= n; i++) {
  cin >> ar[i];
 }

 int even = n / 2 , odd = n - even, ans = 0;
 for(int i = 1; i <= 100; i++) {
  int cnt = 0, gcd1 = 0, gcd2 = 0;
  for(int j = 1; j <= n; j++) {
    if(ar[j] % i == 0 && cnt < min(even, odd)) {
      cnt++;
    }
    else {
      gcd1 = __gcd(gcd1, ar[j]);
    }
  }


  if(cnt  == min(even, odd)) {
    ans = max (ans, i + gcd1);
  }
 }
 cout << ans << endll;
}

int32_t main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
  solve();
}
 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:13:52
Judged At
2024-11-11 03:15:34
Judged By
Score
33
Total Time
16ms
Peak Memory
568.0 KiB