/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 3ms 764.0 KiB
#3 Accepted 96ms 324.0 KiB
#4 Time Exceeded ≥2086ms ≥556.0 KiB
#5 Time Exceeded ≥2090ms ≥568.0 KiB

Code

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

ll gcd_(ll a, ll b) {
    return b==0? a : gcd_(b, a%b);
}

void solve() {
    ll n,k;
    cin>>n>>k;
    vector<ll> arr(n);

    for (ll i=0; i<n; i++) {
        cin>>arr[i];
    }
    vector<ll> dp(n+1,LLONG_MAX);

    dp[1]=0;

    for (ll i =1; i<=n; i++) {
        if(i+1<=n){
            dp[i+1]=min(dp[i+1],dp[i]+k);
        }
        for(ll j=i+1; j<=n; j++){
        ll cost=arr[i-1]/gcd_(arr[i-1],arr[j-1]);
        dp[j]=min(dp[j],dp[i]+cost);
        }
    }
   
    cout << dp[n] << endl;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
return 0;
}

Information

Submit By
Type
Submission
Problem
P1099 Which way to go
Contest
Brain Booster #6
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 17:41:57
Judged At
2024-11-11 02:45:46
Judged By
Score
15
Total Time
≥2090ms
Peak Memory
≥764.0 KiB