/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 49ms 532.0 KiB
#4 Time Exceeded ≥2000ms ≥532.0 KiB
#5 Time Exceeded ≥2100ms ≥788.0 KiB
#6 Time Exceeded ≥2082ms ≥2.805 MiB
#7 Time Exceeded ≥2094ms ≥9.301 MiB
#8 Time Exceeded ≥2098ms ≥5.43 MiB
#9 Time Exceeded ≥2094ms ≥9.363 MiB
#10 Time Exceeded ≥2096ms ≥2.18 MiB
#11 Time Exceeded ≥2100ms ≥2.184 MiB
#12 Time Exceeded ≥2001ms ≥9.367 MiB
#13 Time Exceeded ≥2000ms ≥9.367 MiB
#14 Time Exceeded ≥2101ms ≥18.102 MiB
#15 Time Exceeded ≥2096ms ≥2.711 MiB
#16 Time Exceeded ≥2098ms ≥1.02 MiB
#17 Time Exceeded ≥2097ms ≥1.031 MiB
#18 Time Exceeded ≥2099ms ≥2.781 MiB
#19 Time Exceeded ≥2099ms ≥1.684 MiB
#20 Time Exceeded ≥2099ms ≥1.719 MiB

Code

#include<bits/stdc++.h>
#include <queue>
#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;
        using pii = pair<int, int>;
        priority_queue<pii,vector<pii>,greater<pii>>pq;
        pq.push({0, 0});

        while (!pq.empty()){
            int cost=pq.top().first;
            int index=pq.top().second;
            pq.pop();
            if (cost>m[index]) 
            continue;
            if (index+1<n){
                int new_cost=cost+k;
                if(new_cost<m[index+1]){
                    m[index+1]=new_cost;
                    pq.push({new_cost, index+1});
                }
            }

            for(int j=index+1; j<n; j++){
                int move_cost=a[index]/gcd(a[index], a[j]);
                int new_cost=cost+move_cost;
                if(new_cost<m[j]){
                    m[j]=new_cost;
                    pq.push({new_cost, j});
                }
            }
        }
        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 17:13:26
Judged At
2024-10-03 17:13:26
Judged By
Score
15
Total Time
≥2101ms
Peak Memory
≥18.102 MiB