/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 2ms 324.0 KiB
#3 Accepted 50ms 552.0 KiB
#4 Time Exceeded ≥2082ms ≥672.0 KiB
#5 Time Exceeded ≥2068ms ≥800.0 KiB

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-11-11 02:46:31
Judged By
Score
15
Total Time
≥2082ms
Peak Memory
≥800.0 KiB