/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 209ms 21.984 MiB
#2 Runtime Error corrupted size vs. prev_size 201ms 22.191 MiB
#3 Wrong Answer 220ms 22.203 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[i] = 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], dis[a[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:54:58
Judged At
2024-11-11 02:42:16
Judged By
Score
5
Total Time
220ms
Peak Memory
22.203 MiB