/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 210ms 22.203 MiB
#2 Runtime Error corrupted size vs. prev_size 200ms 22.207 MiB
#3 Accepted 234ms 22.168 MiB
#4 Accepted 256ms 22.223 MiB
#5 Accepted 278ms 22.223 MiB
#6 Accepted 254ms 22.34 MiB
#7 Accepted 251ms 22.977 MiB
#8 Accepted 231ms 22.977 MiB
#9 Accepted 219ms 22.984 MiB
#10 Accepted 216ms 22.953 MiB
#11 Accepted 230ms 22.977 MiB
#12 Accepted 248ms 22.969 MiB
#13 Accepted 260ms 22.977 MiB
#14 Accepted 258ms 23.742 MiB
#15 Accepted 283ms 22.363 MiB
#16 Accepted 262ms 22.398 MiB
#17 Accepted 369ms 22.367 MiB
#18 Accepted 279ms 22.34 MiB
#19 Accepted 275ms 22.352 MiB
#20 Accepted 267ms 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[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], 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:11
Judged At
2024-11-11 02:42:15
Judged By
Score
95
Total Time
369ms
Peak Memory
23.742 MiB