/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 3ms 540.0 KiB
#3 Accepted 89ms 472.0 KiB
#4 Time Exceeded ≥2093ms ≥552.0 KiB
#5 Time Exceeded ≥2083ms ≥568.0 KiB
#6 Time Exceeded ≥2093ms ≥788.0 KiB
#7 Time Exceeded ≥2094ms ≥2.043 MiB
#8 Time Exceeded ≥2091ms ≥2.039 MiB
#9 Time Exceeded ≥2092ms ≥2.035 MiB
#10 Time Exceeded ≥2090ms ≥2.039 MiB
#11 Time Exceeded ≥2069ms ≥2.051 MiB
#12 Time Exceeded ≥2097ms ≥2.043 MiB
#13 Time Exceeded ≥2085ms ≥2.043 MiB
#14 Time Exceeded ≥2091ms ≥3.555 MiB
#15 Time Exceeded ≥2091ms ≥836.0 KiB
#16 Time Exceeded ≥2089ms ≥836.0 KiB
#17 Time Exceeded ≥2096ms ≥764.0 KiB
#18 Time Exceeded ≥2088ms ≥696.0 KiB
#19 Time Exceeded ≥2096ms ≥700.0 KiB
#20 Time Exceeded ≥2090ms ≥700.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-10-03 17:41:57
Judged By
Score
15
Total Time
≥2097ms
Peak Memory
≥3.555 MiB