/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 9ms 1.551 MiB
#3 Accepted 10ms 2.051 MiB
#4 Accepted 10ms 2.051 MiB
#5 Accepted 11ms 2.055 MiB
#6 Accepted 11ms 2.055 MiB
#7 Accepted 13ms 2.934 MiB
#8 Accepted 18ms 3.047 MiB
#9 Accepted 26ms 2.93 MiB
#10 Accepted 43ms 2.949 MiB
#11 Accepted 63ms 2.879 MiB
#12 Accepted 64ms 2.93 MiB
#13 Accepted 61ms 2.934 MiB
#14 Accepted 68ms 5.051 MiB
#15 Accepted 68ms 4.922 MiB
#16 Accepted 80ms 9.312 MiB
#17 Accepted 71ms 1.719 MiB
#18 Accepted 63ms 928.0 KiB

Code


#include <bits/stdc++.h>

using namespace std;

const int M = 1e6 + 3;
const long long inf = 2e18;
long long f[M];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    vector<int> added;
    auto add = [&](int x, int v) {
      if (x <= k) {
        f[x] += v;
        added.push_back(x);
      }
    };
    for (const int u : a) {
      for (int d = 1; d * d <= u; d++) {
        if (u % d == 0) {
          add(d, u);
          if (d * d < u) add(u / d, u);
        }
      }
    }
    long long best = inf, w = 1;
    int S = min(k + 1, (int) added.size() + 2);
    for (int i = 1; i < S; i++) {
      if (f[i] < best) {
        w = i;
        best = f[i];
      }
    }
    for (int x : added) f[x] = 0;
    cout << w << '\n';
  }
  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-05-06 19:46:30
Judged At
2024-11-11 03:31:33
Judged By
Score
100
Total Time
80ms
Peak Memory
9.312 MiB