Submission #1211095

#TimeUsernameProblemLanguageResultExecution timeMemory
1211095PlayVoltzBrunhilda’s Birthday (BOI13_brunhilda)C++20
80.32 / 100
275 ms157572 KiB
#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
#include <cassert>
#include <chrono>
using namespace std;

#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int to[10000005], dp[10000005];

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, q, a;
	cin>>n>>q;
	for (int i=0; i<10000005; ++i)to[i]=INT_MAX/2;
	while (n--){
		cin>>a;
		for (int i=a-1; i<10000005; i+=a)to[i]=min(to[i], i-a+1);
	}
	for (int i=10000003; i>=0; --i)to[i]=min(to[i], to[i+1]);
	for (int i=1; i<10000005; ++i){
		if (to[i]>=i)dp[i]=INT_MAX/2;
		else dp[i]=dp[to[i]]+1;
	}
	while (q--){
		cin>>a;
		if (dp[a]>=INT_MAX/2)cout<<"oo\n";
		else cout<<dp[a]<<"\n";
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...