/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 1979ms 112.387 MiB
#2 Accepted 1987ms 112.637 MiB
#3 Wrong Answer 1856ms 112.801 MiB

Code

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")
using namespace std;

const int maxN = 1e6;
vector<vector<int>> precomputeDivisors() {
  vector<vector<int>> divisors(maxN + 1);
  for (int i = 1; i <= maxN; ++i) {
    for (int j = i; j <= maxN; j += i) {
      divisors[j].push_back(i);
    }
  }
  return divisors;
}

vector<vector<int>> g = precomputeDivisors();

void solve(int cs) {
  int n, x;
  cin >> n >> x;

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  if (x == 1) {
    cout << "1\n";
    return;
  }

  unordered_map<int, int> seen;
  for (auto &it : a) seen[it] += 1;
  int res = 1e9;
  vector<int> vis(x, 0);
  auto check = [&](int k) -> void {
    auto d = g[k];
    int cnt = 0;
    for (auto &i : d) {
      if (seen[i] > 0) {
        vis[i] = true;
      }
    }
    if (seen[k] <= 1) {
      res = min(res, k);
    }
  };
  for (int i = x; i > 1; i--) {
    if (!vis[i])check(i);
  }
  cout << res << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc = 1;
  cin >> tc;
  for (int cs = 1; cs <= tc; cs++) {
    solve(cs);
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1039 Prince Roy, the undisputed ruler of the world
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-11 10:25:39
Judged At
2024-11-11 03:27:39
Judged By
Score
5
Total Time
1987ms
Peak Memory
112.801 MiB