101532024-03-28 19:17:51111Az óvodai lét elviselhetetlen könnyűsége #2cpp17Time limit exceeded 0/1001.588s158088 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define INF (int)1e18

#define MN (int)1e7 + 1

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int M,Q;
	cin>>M>>Q;
	vector<int>v(M);
	for(int i=0;i<M;i++){
		cin>>v[i];
	}
	vector<int>dp(MN,INF);
	dp[0]=0;
	for(int i=1;i<MN;i++){
		for(int j:v){
			if(i-(i%j)>=0){
				dp[i]=min(dp[i],dp[i-(i%j)]+1);
			}
		}
		if(dp[i]<dp[i-1])exit(1);
	}
	while(Q--){
		int N;
		cin>>N;
		cout<<(dp[N]%INF)<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted333ms158088 KiB
2Time limit exceeded1.57s79472 KiB
subtask20/20
3Time limit exceeded1.554s79724 KiB
4Time limit exceeded1.565s79976 KiB
5Time limit exceeded1.57s80144 KiB
6Time limit exceeded1.562s80036 KiB
7Time limit exceeded1.57s80116 KiB
8Time limit exceeded1.565s80104 KiB
9Time limit exceeded1.562s80356 KiB
10Time limit exceeded1.557s80556 KiB
subtask30/10
11Time limit exceeded1.577s80600 KiB
12Time limit exceeded1.577s80804 KiB
13Time limit exceeded1.57s80720 KiB
14Time limit exceeded1.542s80744 KiB
15Time limit exceeded1.574s81012 KiB
16Time limit exceeded1.57s80900 KiB
17Time limit exceeded1.57s81852 KiB
subtask40/15
18Time limit exceeded1.574s81204 KiB
19Time limit exceeded1.554s81064 KiB
20Time limit exceeded1.565s81760 KiB
21Time limit exceeded1.57s81268 KiB
22Time limit exceeded1.557s81740 KiB
23Time limit exceeded1.554s80928 KiB
24Time limit exceeded1.577s80904 KiB
25Time limit exceeded1.549s80908 KiB
26Time limit exceeded1.557s80904 KiB
27Time limit exceeded1.572s81560 KiB
subtask50/55
28Time limit exceeded1.554s81920 KiB
29Time limit exceeded1.557s81976 KiB
30Time limit exceeded1.588s81308 KiB
31Time limit exceeded1.578s81364 KiB
32Time limit exceeded1.549s81516 KiB
33Time limit exceeded1.565s81424 KiB
34Time limit exceeded1.577s81300 KiB
35Time limit exceeded1.562s81236 KiB
36Time limit exceeded1.554s81228 KiB
37Time limit exceeded1.577s81628 KiB
38Time limit exceeded1.577s82160 KiB
39Time limit exceeded1.567s82872 KiB