12322022-03-27 13:56:02Valaki2Az óvodai lét elviselhetetlen könnyűsége #2cpp14Runtime error 20/1001.595s8044 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second

int n, q;
vector<int> v;

void solve() {
    cin >> n >> q;
    v.assign(n, 0);
    int maxi = 0;
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        maxi = max(maxi, v[i]);
    }
    // subtask 3
    /*for(int i = 0; i < q; i++) {
        int x;
        cin >> x;
        cout << (x < maxi ? 1 : 0) << "\n";
    }*/
    vector<int> dp(5001, 0);
    for(int i = 1; i <= 5000; i++) {
        dp[i] = 1e9;
        for(int x : v) {
            dp[i] = min(dp[i], dp[i / x * x] + 1);
        }
    }
    while(q--) {
        int x;
        cin >> x;
        cout << (dp[x] == 1e9 ? 0 : dp[x]) << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted2ms2024 KiB
2Runtime error6ms2076 KiB
subtask220/20
3Accepted3ms2060 KiB
4Accepted3ms2084 KiB
5Accepted3ms2108 KiB
6Accepted3ms2136 KiB
7Accepted6ms2160 KiB
8Accepted28ms2188 KiB
9Accepted59ms2216 KiB
10Accepted101ms2368 KiB
subtask30/10
11Runtime error3ms2404 KiB
12Runtime error8ms2352 KiB
13Runtime error7ms2440 KiB
14Runtime error8ms2456 KiB
15Wrong answer30ms2932 KiB
16Runtime error8ms3000 KiB
17Time limit exceeded1.595s3316 KiB
subtask40/15
18Runtime error71ms3904 KiB
19Runtime error46ms3920 KiB
20Time limit exceeded1.57s3884 KiB
21Runtime error68ms4648 KiB
22Time limit exceeded1.552s4864 KiB
23Runtime error10ms5300 KiB
24Runtime error10ms5280 KiB
25Runtime error10ms5380 KiB
26Runtime error16ms5396 KiB
27Runtime error1.11s6012 KiB
subtask50/55
28Time limit exceeded1.519s5836 KiB
29Time limit exceeded1.549s6840 KiB
30Runtime error181ms7676 KiB
31Runtime error52ms7700 KiB
32Runtime error210ms8044 KiB
33Runtime error70ms5616 KiB
34Runtime error7ms5660 KiB
35Runtime error9ms5620 KiB
36Runtime error225ms5948 KiB
37Runtime error462ms6380 KiB
38Time limit exceeded1.549s6248 KiB
39Time limit exceeded1.524s7256 KiB