/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 76ms 10.695 MiB
#2 Accepted 69ms 10.48 MiB
#3 Accepted 72ms 10.691 MiB
#4 Accepted 69ms 10.703 MiB
#5 Accepted 73ms 10.707 MiB
#6 Accepted 70ms 10.543 MiB
#7 Accepted 67ms 10.465 MiB
#8 Accepted 68ms 10.492 MiB
#9 Accepted 74ms 10.594 MiB
#10 Accepted 64ms 10.582 MiB
#11 Accepted 71ms 10.602 MiB
#12 Accepted 71ms 10.598 MiB
#13 Accepted 72ms 10.703 MiB
#14 Accepted 70ms 10.695 MiB
#15 Time Exceeded ≥2086ms ≥11.508 MiB
#16 Time Exceeded ≥2050ms ≥11.504 MiB
#17 Time Exceeded ≥2087ms ≥12.34 MiB
#18 Accepted 79ms 10.656 MiB
#19 Accepted 371ms 10.805 MiB
#20 Accepted 401ms 10.805 MiB
#21 Accepted 342ms 10.824 MiB
#22 Accepted 349ms 10.828 MiB
#23 Accepted 258ms 10.812 MiB
#24 Accepted 256ms 10.82 MiB
#25 Accepted 179ms 10.816 MiB
#26 Accepted 344ms 10.816 MiB
#27 Accepted 541ms 10.816 MiB
#28 Accepted 444ms 10.82 MiB
#29 Accepted 991ms 10.816 MiB
#30 Time Exceeded ≥2086ms ≥11.082 MiB
#31 Time Exceeded ≥2087ms ≥11.086 MiB
#32 Accepted 237ms 10.77 MiB
#33 Time Exceeded ≥2094ms ≥15.953 MiB
#34 Accepted 96ms 10.785 MiB
#35 Time Exceeded ≥2095ms ≥11.082 MiB

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 = 1e5+ 9;
vector<int> divv[N + 3];
void solve()
{
  int n;
  cin >> n;
  int ar[n + 3];
  map<int, int> mp;
  vector<int> all_div;
  for (int i = 1; i <= n; i++)
  {
    cin >> ar[i];
    for (auto j : divv[ar[i]])
    {
      mp[j]++;
    }
  }
  for (auto i : mp)
    all_div.pb(i.first);

  int even = n / 2, odd = n - even, ans = 0;
  for (int i = 0; i < all_div.size(); i++)
  {

    int ii = all_div[i];

    for (int j = i; j <all_div.size(); j++)
    {
      int jj = all_div[j];
    // cout << ii << " " << jj << endll;
      int both = 0, first = 0, second = 0, flg = 0;
      for (int k = 1; k <= n; k++)
      {
        if (ar[k] % ii == 0 && ar[k] % jj == 0)
        {
          both++;
        }
        else if (ar[k] % ii == 0)
        {
          first++;
        }
        else if (ar[k] % jj == 0)
        {
          second++;
        }
        else
        {
          flg = 1;
          break;
        } 
      }

      if (flg == 0)
      {
        if (first > even && first > odd)
        {
          continue;
        }

        if (second > even && second > odd)
        {
          continue;
        }

        ans = max(ans, ii + jj);
      }
    }
  }
  // cout << all_div.size() << endl;
  cout << ans << endll;
}

int32_t main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;

  for (int i = 1; i <= N; i++)
  {
    for (int j = i; j <= N; j += i)
    {
      divv[j].pb(i);
    }
  }

  cin >> t;
  while (t--)
  {
    solve();
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1077 Even Odd GCD (Hard Version)
Contest
Bangladesh 2.0
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-16 16:40:04
Judged At
2024-10-03 13:26:22
Judged By
Score
80
Total Time
≥2095ms
Peak Memory
≥15.953 MiB