/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 249ms 34.434 MiB
#2 Accepted 264ms 34.324 MiB
#3 Accepted 274ms 34.281 MiB
#4 Accepted 340ms 34.316 MiB
#5 Accepted 424ms 34.398 MiB
#6 Accepted 415ms 34.809 MiB
#7 Accepted 423ms 35.887 MiB
#8 Accepted 349ms 35.914 MiB
#9 Accepted 307ms 36.004 MiB
#10 Accepted 303ms 36.027 MiB
#11 Accepted 290ms 36.027 MiB
#12 Wrong Answer 365ms 35.914 MiB
#13 Accepted 373ms 36.004 MiB
#14 Accepted 379ms 37.531 MiB
#15 Accepted 393ms 34.805 MiB
#16 Accepted 351ms 34.793 MiB
#17 Accepted 666ms 34.805 MiB
#18 Accepted 390ms 34.805 MiB
#19 Accepted 387ms 34.805 MiB
#20 Accepted 381ms 34.805 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:04:51
Judged At
2024-11-11 02:40:23
Judged By
Score
95
Total Time
666ms
Peak Memory
37.531 MiB