/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 200ms 34.465 MiB
#2 Accepted 209ms 34.469 MiB
#3 Accepted 213ms 34.27 MiB
#4 Accepted 245ms 34.492 MiB
#5 Accepted 282ms 34.488 MiB
#6 Accepted 284ms 34.676 MiB
#7 Accepted 284ms 36.0 MiB
#8 Accepted 242ms 35.953 MiB
#9 Accepted 243ms 35.973 MiB
#10 Accepted 225ms 35.957 MiB
#11 Accepted 219ms 35.953 MiB
#12 Accepted 257ms 35.953 MiB
#13 Accepted 269ms 35.953 MiB
#14 Accepted 260ms 37.512 MiB
#15 Accepted 300ms 34.785 MiB
#16 Accepted 255ms 34.77 MiB
#17 Accepted 551ms 34.777 MiB
#18 Accepted 281ms 34.746 MiB
#19 Accepted 285ms 34.785 MiB
#20 Accepted 281ms 34.742 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"

const int N = 2e5 + 5;
const int inf = 1e9;
vector<vector<int>> divs(N);

void prec(){
    for(int i=1 ; i<N ; i++){
        for(int j=i; j<N ; j+=i){
            divs[j].pb(i);
        }
    }
}

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

    vector<int> dp(n+1);
    vector<int> dist(N, inf);

    dp[0] = 0;
    for(auto d: divs[a[0]]){
        dist[d] = a[0] / d;
    }

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

        for(auto d: divs[a[i]]){
            dp[i] = min(dp[i], dist[d]);
        }
        for(auto d: divs[a[i]]){
            dist[d] = min(dist[d], dp[i] + (a[i]/d));
        }
    }

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

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

    prec();

    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 09:34:26
Judged At
2024-10-13 09:34:26
Judged By
Score
100
Total Time
551ms
Peak Memory
37.512 MiB