/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 201ms 22.211 MiB
#2 Wrong Answer 221ms 22.219 MiB
#3 Wrong Answer 222ms 22.207 MiB

Code

#include <bits/stdc++.h>
using namespace std;

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
using ll = long long;

const int INF = 1'000'000'000;
const int MX = 200005;
vector<int> divs[MX];
int dis[MX];

void pre() {
  int i, j;
  for (i = 1; i < MX; ++i) {
    for (j = i; j < MX; j += i) divs[j].push_back(i);
  }
}

int main() {
  FAST;
  pre();
  
  int tc = 1, ti;
  cin >> tc;

  for (ti = 1; ti <= tc; ++ti) {
    int n, k, i, x, ans;
    cin >> n >> k;

    for (i = 0; i < MX; ++i) dis[i] = INF;

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

    dis[a[0]] = 0;

    for (i = 0; i < n; ++i) {
      x = a[i];
      for (int d : divs[x]) {
        dis[x] = min(dis[x], dis[d]);
      }
      for (int d : divs[x]) {
        dis[d] = min(dis[d], dis[x] + x/d);
      }
    }

    ans = (n-1) * k;
    if (n == 1) {
      ans = 0;
    } else if (a[n-1] % a[0] == 0) {
      ans = 1;
    } else {
      for (i = 0; i < n; ++i) {
        ans = min(ans, max(dis[a[i]], 1) + (n-i-1) * k);
      }
    }
    
    cout << ans << "\n";
  }

  return 0;
}

Information

Submit By
Type
Submission
Problem
P1099 Which way to go
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 20:19:40
Judged At
2024-11-11 02:44:37
Judged By
Score
5
Total Time
222ms
Peak Memory
22.219 MiB