/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 339ms 22.328 MiB
#2 Accepted 306ms 22.207 MiB
#3 Accepted 316ms 22.215 MiB
#4 Accepted 306ms 22.219 MiB
#5 Accepted 365ms 22.238 MiB
#6 Accepted 391ms 22.367 MiB
#7 Accepted 407ms 22.977 MiB
#8 Accepted 272ms 22.977 MiB
#9 Accepted 344ms 22.973 MiB
#10 Accepted 322ms 22.98 MiB
#11 Accepted 297ms 22.973 MiB
#12 Accepted 303ms 22.973 MiB
#13 Accepted 323ms 22.98 MiB
#14 Accepted 337ms 23.742 MiB
#15 Accepted 348ms 22.367 MiB
#16 Accepted 322ms 22.359 MiB
#17 Accepted 449ms 22.355 MiB
#18 Accepted 360ms 22.355 MiB
#19 Accepted 344ms 22.367 MiB
#20 Accepted 354ms 22.371 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;
    cin >> n >> k;

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

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

    dp[0] = 0;
    for (int d : divs[a[0]]) {
      dis[d] = a[0]/d;
    }

    for (i = 1; i < n; ++i) {
      dp[i] = dp[i-1] + k;
      for (int d : divs[a[i]]) {
        dp[i] = min(dp[i], dis[d]);
      }
      for (int d : divs[a[i]]) {
        dis[d] = min(dis[d], dp[i] + a[i]/d);
      }
    }
    
    cout << dp[n-1] << "\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-04 18:56:51
Judged At
2024-11-11 02:42:15
Judged By
Score
100
Total Time
449ms
Peak Memory
23.742 MiB