/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 8ms 1.059 MiB
#3 Accepted 120ms 6.895 MiB
#4 Time Exceeded ≥2101ms ≥64.367 MiB
#5 Time Exceeded ≥2107ms ≥120.898 MiB
#6 Time Exceeded ≥2007ms ≥98.23 MiB
#7 Time Exceeded ≥2108ms ≥140.191 MiB
#8 Time Exceeded ≥2103ms ≥39.816 MiB
#9 Time Exceeded ≥2108ms ≥113.137 MiB
#10 Time Exceeded ≥2003ms ≥38.453 MiB
#11 Time Exceeded ≥2107ms ≥109.625 MiB
#12 Time Exceeded ≥2117ms ≥230.695 MiB
#13 Time Exceeded ≥2111ms ≥176.68 MiB
#14 Time Exceeded ≥2114ms ≥208.27 MiB
#15 Time Exceeded ≥2109ms ≥158.035 MiB
#16 Time Exceeded ≥2099ms ≥1.02 MiB
#17 Time Exceeded ≥2100ms ≥1008.0 KiB
#18 Time Exceeded ≥2103ms ≥59.215 MiB
#19 Time Exceeded ≥2103ms ≥53.961 MiB
#20 Time Exceeded ≥2107ms ≥115.453 MiB

Code

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, k, A[200005], vs[200005];

void solve(){
	cin >> n >> k;
	for(int i = 1; i <= n; i++)cin >> A[i], vs[i] = 0;
	int bnd = min(k * (n - 1), A[1] / __gcd(A[1], A[n]));
	queue <int> q[bnd + 1];
	q[0].push(1);
	for(int i = 0; i <= bnd; i++){
		while(!q[i].empty()){
			int j = q[i].front(); q[i].pop();
			if(j == n){
				cout << i << '\n';
				return;
			}
			if(vs[j])continue;
			vs[j] = 1;
			int mn = min(k * (n - j), A[j] / __gcd(A[j], A[n]));
			for(int kk = j + 1; kk <= n; kk++){
				int tot = A[j] / __gcd(A[j], A[kk]);
				if(tot > mn || i + tot > bnd)continue;
				q[i + tot].push(kk);
			}
			if(i + k <= bnd)q[i + k].push(j + 1);
		}
	}
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

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 16:25:28
Judged At
2024-10-03 16:25:28
Judged By
Score
15
Total Time
≥2117ms
Peak Memory
≥230.695 MiB