Wrong Answer
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