/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 2ms 324.0 KiB
#3 Accepted 46ms 536.0 KiB
#4 Time Exceeded ≥2089ms ≥544.0 KiB
#5 Time Exceeded ≥2090ms ≥556.0 KiB

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