Submission #1247018

#TimeUsernameProblemLanguageResultExecution timeMemory
1247018kaiboyBrunhilda’s Birthday (BOI13_brunhilda)C++20
100 / 100
187 ms40092 KiB
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 10000000;

int dp[N + 1];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	int k, q; cin >> k >> q;
	while (k--) {
		int p; cin >> p;
		for (int n = p - 1; n < N; n += p)
			dp[n] = max(dp[n], p - 1);
		dp[N] = max(dp[N], N % p);
	}
	for (int n = N - 1; n; n--)
		dp[n] = max(dp[n], dp[n + 1] - 1);
	for (int n = 1; n <= N; n++)
		dp[n] = !dp[n] || dp[n - dp[n]] == -1 ? -1 : dp[n - dp[n]] + 1;
	while (q--) {
		int n; cin >> n;
		if (dp[n] == -1) {
			cout << "oo\n";
			continue;
		}
		cout << dp[n] << '\n';
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...