/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 69ms 10.703 MiB
#2 Accepted 67ms 10.77 MiB
#3 Accepted 67ms 10.488 MiB
#4 Accepted 67ms 10.629 MiB
#5 Wrong Answer 67ms 10.77 MiB
#6 Accepted 68ms 10.613 MiB
#7 Accepted 69ms 10.699 MiB
#8 Accepted 64ms 10.695 MiB
#9 Accepted 65ms 10.77 MiB
#10 Accepted 67ms 10.77 MiB
#11 Accepted 65ms 10.594 MiB
#12 Accepted 64ms 10.754 MiB
#13 Accepted 67ms 10.77 MiB
#14 Accepted 68ms 10.641 MiB
#15 Accepted 99ms 12.02 MiB
#16 Accepted 106ms 13.828 MiB
#17 Accepted 386ms 23.258 MiB
#18 Wrong Answer 62ms 10.871 MiB
#19 Wrong Answer 263ms 18.27 MiB
#20 Wrong Answer 310ms 18.508 MiB
#21 Wrong Answer 244ms 22.871 MiB
#22 Wrong Answer 242ms 22.699 MiB
#23 Wrong Answer 176ms 22.82 MiB
#24 Wrong Answer 163ms 23.543 MiB
#25 Wrong Answer 123ms 18.926 MiB
#26 Wrong Answer 223ms 23.086 MiB
#27 Wrong Answer 289ms 23.543 MiB
#28 Accepted 193ms 23.816 MiB
#29 Wrong Answer 360ms 26.582 MiB
#30 Wrong Answer 907ms 59.074 MiB
#31 Wrong Answer 746ms 59.066 MiB
#32 Wrong Answer 162ms 17.082 MiB
#33 Accepted 160ms 19.055 MiB
#34 Accepted 109ms 11.762 MiB
#35 Wrong Answer 1805ms 59.168 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-10-03 13:25:46
Judged By
Score
53
Total Time
1805ms
Peak Memory
59.168 MiB