/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 393ms 34.324 MiB
#2 Accepted 312ms 34.277 MiB
#3 Accepted 328ms 34.262 MiB
#4 Accepted 430ms 34.406 MiB
#5 Accepted 545ms 34.434 MiB
#6 Accepted 529ms 34.793 MiB
#7 Accepted 494ms 36.023 MiB
#8 Accepted 430ms 36.02 MiB
#9 Accepted 398ms 36.016 MiB
#10 Accepted 406ms 36.004 MiB
#11 Accepted 381ms 36.023 MiB
#12 Accepted 498ms 36.02 MiB
#13 Accepted 513ms 36.02 MiB
#14 Accepted 522ms 37.551 MiB
#15 Accepted 537ms 34.797 MiB
#16 Accepted 476ms 34.793 MiB
#17 Accepted 916ms 34.801 MiB
#18 Accepted 567ms 34.797 MiB
#19 Accepted 583ms 34.797 MiB
#20 Accepted 621ms 34.793 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
vector<ll>ar[200003];
ll dis[200003];
ll mxN=200000;
void seive()
{
    for(int i=1;i<=mxN;i++)
    {
        for(int j=i;j<=mxN;j+=i)
        {
            ar[j].push_back(i);
        }
    }
}
int main()
{
    ll tc;
    cin>>tc;
    seive();
    while(tc--)
    {
        ll n,k;
        cin>>n>>k;
        vector<ll>v(n),dp(n+1,2e9);
        for(int i=0;i<n;i++)
            cin>>v[i];
        dp[0]=0;
        for(int i=1;i<=mxN;i++)
        {
            dis[i]=2e9;
           
        }
        for(auto it:ar[v[0]])
        {
            dis[it]=min(dis[it],v[0]/it);
        }
        for(int i=1;i<n;i++)
        {
            dp[i]=min(dp[i],dp[i-1]+k);
            for(auto it:ar[v[i]])
            {
                dp[i]=min(dp[i],dis[it]);
            }
            for(auto it:ar[v[i]])
            {
                dis[it]=min(dis[it],dp[i]+(v[i]/it));
            }
        }
        cout<<dp[n-1]<<endl;
    }
    
}

Information

Submit By
Type
Submission
Problem
P1099 Which way to go
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-05 07:05:34
Judged At
2024-11-11 02:40:22
Judged By
Score
100
Total Time
916ms
Peak Memory
37.551 MiB