Submission #256245

#TimeUsernameProblemLanguageResultExecution timeMemory
256245shayan_pBrunhilda’s Birthday (BOI13_brunhilda)C++14
100 / 100
413 ms144668 KiB
// And you curse yourself for things you never done

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int maxn = 1e5 + 10, MAX = 1e7 + 10, mod = 1e9 + 7, inf = 1e9 + 10; //////

int a[maxn], dp[MAX];
int ext[MAX];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();

    int n, q;
    cin >> n >> q;
    int lm = 1;
    for(int i = 0; i < n; i++){
	cin >> a[i];
        lm = min(1ll * lm * a[i], ll(MAX));
	for(int j = 0; j < MAX; j+= a[i])
	    ext[j] = max(ext[j], j + a[i]);
    }
    vector<int> vec;
    int pt = 0;
    vec.PB(0);
    for(int i = 1; i < lm; i++){
	while(pt < sz(vec) && ext[vec[pt]] <= i)
	    pt++;
	dp[i] = 1 + dp[ vec[pt] ];
	if(ext[i] > i)
	    vec.PB(i);
    }
    while(q--){
	int x;
	cin >> x;
	if(x >= lm)
	    cout << "oo\n";
	else
	    cout << dp[x] << "\n";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...