Submission #1126537

#TimeUsernameProblemLanguageResultExecution timeMemory
1126537AgageldiBrunhilda’s Birthday (BOI13_brunhilda)C++20
97.14 / 100
1099 ms156808 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define sz(s) (int)s.size()
#define N 10000005

ll n, m, q, a[N], ad[N], t, dp[N];

int main () {
	ios::sync_with_stdio(0);cin.tie(0);
	cin >> m >> q;
	for(int i = 1; i <= m; i++){
		cin >> a[i];
		for(int j = a[i]; j <= 1e7 + 1; j += a[i]) {
			ad[j - 1] = max(ad[j - 1], a[i] - 1);
		}
		ad[10000000] = max(ad[10000000], (10000000 % a[i]));
	}
	for(int i = 1e7; i >= 1; i--) {
		ad[i] = max(ad[i], ad[i + 1] - 1);
	}
	for(int i = 1; i <= 1e7; i++) {
		if(!ad[i] || dp[i - ad[i]] == -1) dp[i] = -1;
	}
	for(int i = 1; i <= q; i++) {
		int x, cnt = 0;
		cin >> x;
		if(dp[x] == -1) {
			cout << "oo\n";
			continue;
		}
		while(x) {
			t = x;
			x -= ad[x];
			cnt++;
		}
		cout << cnt << '\n';
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...