/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 320.0 KiB
#3 Accepted 87ms 532.0 KiB
#4 Time Exceeded ≥2100ms ≥532.0 KiB
#5 Time Exceeded ≥2099ms ≥576.0 KiB
#6 Time Exceeded ≥2099ms ≥788.0 KiB
#7 Time Exceeded ≥2099ms ≥2.066 MiB
#8 Time Exceeded ≥2099ms ≥2.02 MiB
#9 Time Exceeded ≥2100ms ≥2.02 MiB
#10 Time Exceeded ≥2100ms ≥2.02 MiB
#11 Time Exceeded ≥2100ms ≥2.02 MiB
#12 Time Exceeded ≥2100ms ≥2.07 MiB
#13 Time Exceeded ≥2097ms ≥2.062 MiB
#14 Time Exceeded ≥2101ms ≥3.52 MiB
#15 Time Exceeded ≥2099ms ≥788.0 KiB
#16 Time Exceeded ≥2099ms ≥788.0 KiB
#17 Time Exceeded ≥2100ms ≥788.0 KiB
#18 Time Exceeded ≥2101ms ≥788.0 KiB
#19 Time Exceeded ≥2099ms ≥788.0 KiB
#20 Time Exceeded ≥2100ms ≥788.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}
void solve(){
	ll n, k;
	cin >> n >> k;
	vector<ll>ar(n);
	for(auto &a : ar) cin >> a;

	vector<ll>cost(n + 1, LLONG_MAX);
	cost[0] = 0; 

    
    for (int i = 0; i < n; i++) {
        if (i + 1 < n) {
            cost[i + 1] = min(cost[i + 1], cost[i] + k);
        }

    for (int j = i + 1; j < n; j++) {
        ll movecost = ar[i] / gcd(ar[i], ar[j]);
        cost[j] = min(cost[j], cost[i] + movecost);
    }
	}
    cout << cost[n - 1] << '\n';
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}

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 15:53:23
Judged At
2024-10-03 15:53:23
Judged By
Score
15
Total Time
≥2101ms
Peak Memory
≥3.52 MiB