/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 4ms 332.0 KiB
#2 Accepted 14ms 552.0 KiB
#3 Accepted 150ms 552.0 KiB
#4 Accepted 137ms 552.0 KiB
#5 Accepted 148ms 560.0 KiB
#6 Accepted 146ms 556.0 KiB
#7 Accepted 151ms 560.0 KiB
#8 Accepted 246ms 552.0 KiB
#9 Accepted 353ms 560.0 KiB
#10 Accepted 720ms 564.0 KiB
#11 Time Exceeded ≥1051ms ≥332.0 KiB
#12 Time Exceeded ≥1066ms ≥484.0 KiB
#13 Time Exceeded ≥1086ms ≥568.0 KiB
#14 Time Exceeded ≥1042ms ≥572.0 KiB
#15 Time Exceeded ≥1056ms ≥576.0 KiB
#16 Time Exceeded ≥1037ms ≥572.0 KiB
#17 Time Exceeded ≥1073ms ≥592.0 KiB
#18 Time Exceeded ≥1008ms ≥576.0 KiB
#19 Time Exceeded ≥1019ms ≥572.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;

#define print(a) for(auto x:a)cout<<x<<' ';cout<<'\n';
#define debug(x) cout<<#x<<" "<<x<<'\n'
#define int   long long int

const int M = 1e9 + 7;
const int N = 2e5 + 10;

void solve(){
   int n; cin >> n;
   vector<int> a(n);

   for(int i = 0; i < n; i++){
      cin >> a[i];
   }
   int res = 0;

   int even = n / 2, odd = (n + 1) / 2;

   for(int i = 1; i <= 100; i++){
      for(int j = 1; j <= 100; j++){
         int o = 0, e = 0, both = 0;
         for(int k = 0; k < n; k++){
            if(a[k] % i == 0 && a[k] % j == 0)both++;
            else if(a[k] % i == 0)e++;
            else if(a[k] % j == 0)o++;
         }
         int mn = max(0ll, min(both, even - e));
         both -= mn;
         e += mn;
         o += both;
         if(e == even && o == odd)res = max(res, i + j);
      }
   }

   cout << res << '\n';
}


signed main() {
   ios_base::sync_with_stdio (0);
   cin.tie (0);

   int t = 1;   cin >> t;
   for (int tc = 1; tc <= t; tc++) {
      //cout<<"Case "<<tc<<": ";
      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 17:15:05
Judged At
2024-10-03 13:23:09
Judged By
Score
25
Total Time
≥1086ms
Peak Memory
≥592.0 KiB