Time Exceeded
Code
#include<bits/stdc++.h>
#include <numeric>
#include <limits>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n,k; cin>>n>>k;
vector<int>a(n);
for(int i=0; i<n; i++){
cin>>a[i];
}
vector<int>m(n, numeric_limits<int>::max());
m[0]=0;
for(int i=0; i<n; i++){
if(i+1<n){
m[i+1]=min(m[i+1], m[i]+k);
}
for(int j=i+1; j<n; j++) {
int cost=a[i]/gcd(a[i],a[j]);
m[j]=min(m[j], m[i]+cost);
}
}
cout<<m[n-1]<<endl;
}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1099 Which way to go
- Contest
- Brain Booster #6
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2024-10-03 16:17:02
- Judged At
- 2024-12-17 11:35:05
- Judged By
- Score
- 15
- Total Time
- ≥2090ms
- Peak Memory
- ≥556.0 KiB