/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 76ms 10.68 MiB
#2 Accepted 71ms 10.641 MiB
#3 Accepted 74ms 10.703 MiB
#4 Accepted 66ms 10.574 MiB
#5 Wrong Answer 67ms 10.801 MiB
#6 Accepted 68ms 10.805 MiB
#7 Accepted 69ms 10.703 MiB
#8 Accepted 72ms 10.797 MiB
#9 Accepted 71ms 10.809 MiB
#10 Accepted 69ms 10.637 MiB
#11 Accepted 74ms 10.805 MiB
#12 Accepted 75ms 10.836 MiB
#13 Accepted 76ms 10.816 MiB
#14 Accepted 76ms 10.527 MiB
#15 Accepted 109ms 11.832 MiB
#16 Accepted 114ms 13.949 MiB
#17 Accepted 404ms 23.285 MiB
#18 Wrong Answer 78ms 10.887 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;
  vector<int> v;
  for (int i = 1; i <= n; i++)
  {
    cin >> ar[i];

    for (auto j : divv[ar[i]])
    {
      v.pb(j);
    }
  }
  for (auto i : v)
  {
    if (vis[i] == 0)
      all_div.pb(i);
    vis[i] = 1;
  }

  for (auto i : v)
    vis[i] = 0;

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

    int ii = all_div[i];

    for (int j = i; j < all_div.size() && j <= 50; 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:50:19
Judged At
2024-11-11 03:13:49
Judged By
Score
46
Total Time
404ms
Peak Memory
23.285 MiB