/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 540.0 KiB
#2 Accepted 3ms 500.0 KiB
#3 Accepted 8ms 736.0 KiB
#4 Accepted 8ms 532.0 KiB
#5 Accepted 9ms 768.0 KiB
#6 Accepted 10ms 744.0 KiB
#7 Accepted 9ms 748.0 KiB
#8 Accepted 11ms 752.0 KiB
#9 Accepted 15ms 744.0 KiB
#10 Accepted 20ms 752.0 KiB
#11 Accepted 58ms 744.0 KiB
#12 Accepted 104ms 796.0 KiB
#13 Accepted 42ms 752.0 KiB
#14 Accepted 53ms 992.0 KiB
#15 Accepted 50ms 996.0 KiB
#16 Accepted 36ms 820.0 KiB
#17 Accepted 49ms 812.0 KiB
#18 Accepted 32ms 740.0 KiB
#19 Accepted 22ms 740.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];
   }

   vector<vector<int>>x(101, vector<int>(101,0));
   vector<vector<int>> y = x;

   for(int i = 0; i < n; i++){
      vector<int> d;
      for(int j = 1; j * j <= a[i]; j++){
         if(a[i] % j == 0){
            d.push_back(j);
            if(a[i] / j != j)d.push_back(a[i] / j);
         }
      }
      sort(d.begin(), d.end());

      for(auto it : d){
         for(auto it1 : d){
            x[it][it1]++;
         }
      }

      for(auto x : d){
         for(int j = 1; j <= 100; j++){
            if(a[i] % j == 0)continue;
            y[x][j]++;
         }
      }
   }


   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 = x[i][j];
         if(i != j){
            o = y[i][j], e = y[j][i];
         }
         
         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:31:17
Judged At
2024-08-16 17:31:17
Judged By
Score
100
Total Time
104ms
Peak Memory
996.0 KiB