168282025-05-13 18:30:29TaxiradioAz óvodai lét elviselhetetlen könnyűsége #2cpp17Runtime error 0/100118ms131072 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int m = 20000000;

int dp[10000009];

vector<int> b[10000009];


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int n , q; cin >> n >> q;
    vector<int> a;
    for(int i = 0; i < n; i++){
        int y; cin >> y;
        a.push_back(y);
    }
    sort(a.begin() , a.end());
    a.erase(unique(a.begin() , a.end()) , a.end());
    dp[0] = 0;
    queue<array<int , 2>> c; 
    for(int i = 0; i < a.size();i++){
        c.push({i , 0});
        for(int j = 0; j*a[i] < 10000009; j++){
            b[j*a[i]].push_back(i);
        }
    }
    vector<int> k(a.size() , 0);
    for(int i = 1; i < 10000009; i++){
        for(int x : b[i]){
            k[x] = i;
            c.push({x , i});
        }
        while(c.front()[1] != k[c.front()[0]])c.pop();
        if(c.front()[1] == i)dp[i] = m;else dp[i] = dp[c.front()[1]]+1;
    }
    while(q--){
        int u; cin >> u;
        cout<< (dp[u]>u?0:dp[u]) << "\n";
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Runtime error115ms131072 KiB
2Runtime error98ms131072 KiB
subtask20/20
3Runtime error118ms131072 KiB
4Runtime error97ms131072 KiB
5Runtime error96ms131072 KiB
6Runtime error116ms131072 KiB
7Runtime error116ms131072 KiB
8Runtime error115ms131072 KiB
9Runtime error115ms131072 KiB
10Runtime error94ms131072 KiB
subtask30/10
11Runtime error93ms131072 KiB
12Runtime error115ms131072 KiB
13Runtime error94ms131072 KiB
14Runtime error115ms131072 KiB
15Runtime error114ms131072 KiB
16Runtime error93ms131072 KiB
17Runtime error115ms131072 KiB
subtask40/15
18Runtime error94ms131072 KiB
19Runtime error115ms131072 KiB
20Runtime error94ms131072 KiB
21Runtime error114ms131072 KiB
22Runtime error115ms131072 KiB
23Runtime error114ms131072 KiB
24Runtime error93ms131072 KiB
25Runtime error94ms131072 KiB
26Runtime error94ms131072 KiB
27Runtime error112ms131072 KiB
subtask50/55
28Runtime error96ms131072 KiB
29Runtime error115ms131072 KiB
30Runtime error115ms131072 KiB
31Runtime error115ms131072 KiB
32Runtime error96ms131072 KiB
33Runtime error116ms131072 KiB
34Runtime error115ms131072 KiB
35Runtime error92ms131072 KiB
36Runtime error115ms131072 KiB
37Runtime error115ms131072 KiB
38Runtime error93ms131072 KiB
39Runtime error93ms131072 KiB