/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 261ms 34.426 MiB
#2 Accepted 274ms 34.312 MiB
#3 Accepted 279ms 34.359 MiB
#4 Accepted 362ms 34.273 MiB
#5 Accepted 422ms 34.395 MiB
#6 Accepted 381ms 34.766 MiB
#7 Accepted 386ms 36.023 MiB
#8 Accepted 345ms 36.035 MiB
#9 Accepted 321ms 36.02 MiB
#10 Accepted 307ms 36.008 MiB
#11 Accepted 300ms 36.008 MiB
#12 Wrong Answer 378ms 35.863 MiB
#13 Accepted 370ms 36.023 MiB
#14 Accepted 357ms 37.473 MiB
#15 Accepted 361ms 34.805 MiB
#16 Accepted 363ms 34.797 MiB
#17 Accepted 694ms 34.801 MiB
#18 Accepted 385ms 34.805 MiB
#19 Accepted 370ms 34.809 MiB
#20 Accepted 380ms 34.801 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,1e9);
        for(int i=0;i<n;i++)
            cin>>v[i];
        dp[0]=0;
        for(int i=1;i<=mxN;i++)
        {
            dis[i]=1e9;
           
        }
        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:04:23
Judged At
2024-11-11 02:40:24
Judged By
Score
95
Total Time
694ms
Peak Memory
37.473 MiB