/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Accepted 3ms 508.0 KiB
#3 Accepted 98ms 320.0 KiB
#4 Time Exceeded ≥2096ms ≥628.0 KiB
#5 Time Exceeded ≥2090ms ≥724.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
ll dp[200004];
ll ar[200004];
ll n,k;
ll ok(ll i)
{
    if(i>=n-1)
        return 0;
 
    if(dp[i]!=-1) return dp[i];
       ll op=INT_MAX;
    for(int j=i+1;j<n;j++)
    {
        ll u=(j-i)*k;
        op=min({op,u+ok(j),(ar[i]/__gcd(ar[i],ar[j]))+ok(j)});
        
    }
    return dp[i]=op;
}
int main()
{
    ll tc;
    cin>>tc;
    while(tc--)
    {
       cin>>n>>k;
        
        for(int i=0;i<=n;i++){
            dp[i]=-1;
            ar[i]=0;
        }
        for(int i=0;i<n;i++)
            cin>>ar[i];
        ll op=ok(0);
        cout<<op<<endl;
        
        

    }
}

Information

Submit By
Type
Submission
Problem
P1099 Which way to go
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-04 18:11:55
Judged At
2024-11-11 02:42:24
Judged By
Score
15
Total Time
≥2096ms
Peak Memory
≥724.0 KiB