Submission #577108

# Submission time Handle Problem Language Result Execution time Memory
577108 2022-06-14T05:47:54 Z goodluck2020 Brunhilda’s Birthday (BOI13_brunhilda) C++14
100 / 100
278 ms 80780 KB
#include <bits/stdc++.h>
#define task "GROUP"
#define MASK(n) (1ll << (n))
#define getBit(bit, i) (((bit) >> (i)) & 1)
using namespace std;
using lli = long long;
using pii = pair<int, int>;
const int N = 1e7 + 1;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;

int dp[N], n, q, nxt[N];
vector<int> a;

void readInput() {
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        int x; cin >> x;
        a.push_back(x);
    }
    sort(a.begin(), a.end());
    a.resize(unique(a.begin(), a.end()) - a.begin());
    for (auto x: a)
        for (int i = x; i < N; i += x)
            nxt[i] = x;
}

bool minimize(int &a, int b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

void solve() {
    queue<int> heap;
    for (int i = 1; i < a.back(); i++) heap.push(i);
    for (int i = a.back(); i < N; i++) dp[i] = INF;
    while (!heap.empty()) {
        int u = heap.front(); heap.pop();
        int x = nxt[u];
        for (int i = min(x - 1, N - 1 - u); i >= 1; i--)
            if (minimize(dp[u + i], dp[u] + 1)) heap.push(u + i);
            else break;
    }
    while (q--) {
        int x; cin >> x;
        if (dp[x] == INF) cout << "oo";
        else cout << dp[x] + 1;
        cout << '\n';
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int t = 1;
    while (t--) {
        readInput();
        solve();
    }
    return 0;
}

Compilation message

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
brunhilda.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 37 ms 78472 KB Output is correct
2 Correct 111 ms 78588 KB Output is correct
3 Correct 46 ms 78540 KB Output is correct
4 Correct 81 ms 78600 KB Output is correct
5 Correct 115 ms 78580 KB Output is correct
6 Correct 44 ms 78536 KB Output is correct
7 Correct 46 ms 78484 KB Output is correct
8 Correct 53 ms 78488 KB Output is correct
9 Correct 124 ms 78576 KB Output is correct
10 Correct 135 ms 78560 KB Output is correct
11 Correct 139 ms 78640 KB Output is correct
12 Correct 83 ms 78540 KB Output is correct
13 Correct 192 ms 78492 KB Output is correct
14 Correct 185 ms 78580 KB Output is correct
15 Correct 123 ms 78580 KB Output is correct
16 Correct 104 ms 78496 KB Output is correct
17 Correct 120 ms 78492 KB Output is correct
18 Correct 81 ms 78600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 78912 KB Output is correct
2 Correct 119 ms 80748 KB Output is correct
3 Correct 223 ms 79992 KB Output is correct
4 Correct 136 ms 78656 KB Output is correct
5 Correct 205 ms 79100 KB Output is correct
6 Correct 109 ms 78624 KB Output is correct
7 Correct 120 ms 78808 KB Output is correct
8 Correct 136 ms 78616 KB Output is correct
9 Correct 227 ms 79176 KB Output is correct
10 Correct 222 ms 80100 KB Output is correct
11 Correct 244 ms 79184 KB Output is correct
12 Correct 165 ms 78728 KB Output is correct
13 Correct 108 ms 78728 KB Output is correct
14 Correct 133 ms 78640 KB Output is correct
15 Correct 211 ms 79028 KB Output is correct
16 Correct 119 ms 80780 KB Output is correct
17 Correct 183 ms 78564 KB Output is correct
18 Correct 228 ms 79952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 243 ms 79036 KB Output is correct
2 Correct 244 ms 78960 KB Output is correct
3 Correct 270 ms 79576 KB Output is correct
4 Correct 182 ms 79024 KB Output is correct
5 Correct 161 ms 80004 KB Output is correct
6 Correct 205 ms 78928 KB Output is correct
7 Correct 243 ms 80184 KB Output is correct
8 Correct 217 ms 78928 KB Output is correct
9 Correct 242 ms 78952 KB Output is correct
10 Correct 173 ms 78672 KB Output is correct
11 Correct 180 ms 78652 KB Output is correct
12 Correct 176 ms 78668 KB Output is correct
13 Correct 237 ms 79052 KB Output is correct
14 Correct 150 ms 79104 KB Output is correct
15 Correct 183 ms 78628 KB Output is correct
16 Correct 199 ms 78648 KB Output is correct
17 Correct 213 ms 78928 KB Output is correct
18 Correct 237 ms 79060 KB Output is correct
19 Correct 112 ms 78796 KB Output is correct
20 Correct 232 ms 79604 KB Output is correct
21 Correct 164 ms 79120 KB Output is correct
22 Correct 278 ms 79668 KB Output is correct
23 Correct 183 ms 78916 KB Output is correct
24 Correct 124 ms 78924 KB Output is correct
25 Correct 182 ms 78924 KB Output is correct
26 Correct 168 ms 78924 KB Output is correct
27 Correct 263 ms 80040 KB Output is correct
28 Correct 119 ms 78920 KB Output is correct
29 Correct 266 ms 79604 KB Output is correct
30 Correct 247 ms 79340 KB Output is correct
31 Correct 166 ms 78680 KB Output is correct
32 Correct 162 ms 78900 KB Output is correct
33 Correct 110 ms 78844 KB Output is correct
34 Correct 211 ms 80196 KB Output is correct
35 Correct 126 ms 79024 KB Output is correct
36 Correct 264 ms 79620 KB Output is correct
37 Correct 164 ms 79988 KB Output is correct
38 Correct 199 ms 78928 KB Output is correct
39 Correct 144 ms 78860 KB Output is correct
40 Correct 191 ms 78844 KB Output is correct
41 Correct 179 ms 80500 KB Output is correct
42 Correct 200 ms 78912 KB Output is correct