Submission #1211091

#TimeUsernameProblemLanguageResultExecution timeMemory
1211091PlayVoltzBrunhilda’s Birthday (BOI13_brunhilda)C++20
12.54 / 100
1105 ms235592 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[20000005], 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<20000005; ++i)to[i]=INT_MAX/2;
	while (n--){
		cin>>a;
		for (int i=0; i<20000005; i+=a)to[i+a-1]=min(to[i+a-1], i);
	}
	for (int i=20000003; 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...