/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 5ms 3.746 MiB
#2 Accepted 6ms 3.48 MiB
#3 Accepted 99ms 3.609 MiB
#4 Time Exceeded ≥2068ms ≥3.57 MiB
#5 Time Exceeded ≥2020ms ≥3.574 MiB

Code

// PIPRA ||  HABIB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define int        long long int
#define pb         push_back
#define all(x)     x.begin(),x.end()
#define allr(x)    x.rbegin(),x.rend()
#define ii         pair<int,int>
#define endl       "\n"

template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for (const auto &x : v) os << " " << x;
        return os << '}';
}
using orderedTree = tree<int, null_type, less<int>, 
rb_tree_tag, tree_order_statistics_node_update>;

int n, k;
const int N = 2e5 + 5;
const int inf = 1e8;
vector<int> a(N);
vector<int> dp(N);

void pipra(){
    cin >> n >> k;
    for(int i=0 ; i<n ; i++)
        cin >> a[i];

    for(int i=0 ; i<=n ; i++)
        dp[i] = inf;
    dp[0] = 0;

    for(int i=1 ; i<n ; i++){
        dp[i] = dp[i-1] + k;
        int k = max((int)0, i-1000);

        for(int j=i-1 ; j>=0 ; j--){
            dp[i] = min(dp[i], (a[j]/__gcd(a[i], a[j])) + dp[j]);
        }
    }

    cout << dp[n-1] << endl;
}

int32_t main(){
    // HABIB
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); cout.tie(NULL);

    int t;    cin>>t;
    while(t--) {
        pipra();
    }
    return 0 ;
}

Information

Submit By
Type
Submission
Problem
P1099 Which way to go
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-13 07:45:42
Judged At
2024-11-11 02:37:17
Judged By
Score
15
Total Time
≥2068ms
Peak Memory
≥3.746 MiB