/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 80ms 10.594 MiB
#2 Wrong Answer 73ms 10.602 MiB
#3 Wrong Answer 67ms 10.672 MiB
#4 Wrong Answer 68ms 10.699 MiB
#5 Accepted 71ms 10.711 MiB
#6 Accepted 79ms 10.492 MiB
#7 Accepted 68ms 10.578 MiB
#8 Accepted 67ms 10.473 MiB
#9 Wrong Answer 69ms 10.703 MiB
#10 Accepted 71ms 10.621 MiB
#11 Wrong Answer 88ms 10.574 MiB
#12 Accepted 74ms 10.527 MiB
#13 Accepted 73ms 10.582 MiB
#14 Accepted 71ms 10.695 MiB
#15 Accepted 83ms 10.785 MiB
#16 Wrong Answer 107ms 10.824 MiB
#17 Wrong Answer 175ms 11.086 MiB
#18 Accepted 91ms 10.539 MiB
#19 Accepted 279ms 10.805 MiB
#20 Wrong Answer 335ms 10.574 MiB
#21 Wrong Answer 290ms 10.82 MiB
#22 Accepted 311ms 10.824 MiB
#23 Accepted 203ms 10.82 MiB
#24 Accepted 210ms 10.816 MiB
#25 Accepted 141ms 10.816 MiB
#26 Accepted 253ms 10.812 MiB
#27 Accepted 454ms 10.824 MiB
#28 Accepted 170ms 10.832 MiB
#29 Accepted 613ms 10.816 MiB
#30 Time Exceeded ≥2088ms ≥11.086 MiB
#31 Wrong Answer 1129ms 11.086 MiB
#32 Wrong Answer 90ms 10.781 MiB
#33 Wrong Answer 71ms 11.086 MiB
#34 Wrong Answer 75ms 10.789 MiB
#35 Time Exceeded ≥2086ms ≥11.086 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];
int vis[N + 4];
void solve()
{
  int n;
  cin >> n;
  int ar[n + 3];
  vector<int> all_div, backup;
  map<int, int> mp;
  vector<int> v;
  for (int i = 1; i <= n; i++)
  {
    cin >> ar[i];
    if (i == 1)
    {
      for (auto j : divv[ar[i]])
      {
        all_div.push_back(j);
        mp[j]++;
      }
    }
  }

  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 k = 1; k <= n; k++)
    {
      if (ar[k] % ii != 0)
      {
        for (auto ff : divv[ar[k]])
        {
          mp[ff]++;
        }
        break;
        ;
      }
    }
  }

  for (auto i : mp)
    backup.pb(i.first);
  all_div = backup;

  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 17:09:15
Judged At
2024-10-03 13:23:48
Judged By
Score
58
Total Time
≥2088ms
Peak Memory
≥11.086 MiB