Submission #1015954

# Submission time Handle Problem Language Result Execution time Memory
1015954 2024-07-07T06:35:57 Z caterpillow Brunhilda’s Birthday (BOI13_brunhilda) C++17
3.33333 / 100
173 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using ll = long long;
using pl = pair<ll, ll>;
using pi = pair<int, int>;
#define vt vector
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end() 
#define size(x) ((int) (x).size())
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ROF(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0R(i, b) FOR (i, 0, b)
#define endl '\n'
const ll INF = 1e18;
const int inf = 1e9;

const int maxn = 1e7 + 1;

int m, qs; 
int dp[maxn];
vt<int> primes, ans;
vt<pi> queries;
vt<int> evs[maxn];
queue<pi> q;

main() {
    cin.tie(0)->sync_with_stdio(0);
    
    cin >> m >> qs;
    primes.resize(m);
    F0R (i, m) cin >> primes[i]; 
    for (int p : primes) {
        int x = p;
        while (x < maxn) {
            evs[x].pb(p);
            x += p;;
        }
    }

    queries.resize(qs);
    F0R (i, qs) cin >> queries[i].f, queries[i].s = i;
    sort(all(queries));
    reverse(all(queries));
    ans.resize(qs, -1);

    for (int p : primes) {
        q.push({0, p});
    }

    FOR (i, 1, maxn) {
        for (int p : evs[i]) {
            q.push({i, p});
        }
        cerr << size(q) << endl;
        while (q.front().f + q.front().s <= i) {
            q.push({q.front().f + q.front().s, q.front().s});
            q.pop();
        }
        if (q.front().f == i) break;
        dp[i] = dp[q.front().f] + 1;
        while (size(queries) && queries.back().f == i) {
            ans[queries.back().s] = dp[i];
            queries.pop_back();
        }
        if (!size(queries)) break;
    }
    F0R (i, qs) {
        if (ans[i] == -1) cout << "oo\n"; 
        else cout << ans[i] << endl;
    }
}

Compilation message

brunhilda.cpp:33:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   33 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Runtime error 120 ms 262144 KB Execution killed with signal 9
2 Runtime error 134 ms 262144 KB Execution killed with signal 9
3 Runtime error 109 ms 262144 KB Execution killed with signal 9
4 Correct 152 ms 259848 KB Output is correct
5 Runtime error 122 ms 262144 KB Execution killed with signal 9
6 Runtime error 123 ms 262144 KB Execution killed with signal 9
7 Runtime error 108 ms 262144 KB Execution killed with signal 9
8 Runtime error 110 ms 262144 KB Execution killed with signal 9
9 Runtime error 110 ms 262144 KB Execution killed with signal 9
10 Runtime error 112 ms 262144 KB Execution killed with signal 9
11 Runtime error 121 ms 262144 KB Execution killed with signal 9
12 Correct 123 ms 253268 KB Output is correct
13 Runtime error 103 ms 262144 KB Execution killed with signal 9
14 Runtime error 110 ms 262144 KB Execution killed with signal 9
15 Runtime error 110 ms 262144 KB Execution killed with signal 9
16 Runtime error 120 ms 262144 KB Execution killed with signal 9
17 Runtime error 111 ms 262144 KB Execution killed with signal 9
18 Correct 173 ms 259924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 118 ms 262144 KB Execution killed with signal 9
2 Runtime error 117 ms 262144 KB Execution killed with signal 9
3 Runtime error 111 ms 262144 KB Execution killed with signal 9
4 Runtime error 118 ms 262144 KB Execution killed with signal 9
5 Runtime error 118 ms 262144 KB Execution killed with signal 9
6 Runtime error 107 ms 262144 KB Execution killed with signal 9
7 Runtime error 114 ms 262144 KB Execution killed with signal 9
8 Runtime error 119 ms 262144 KB Execution killed with signal 9
9 Runtime error 111 ms 262144 KB Execution killed with signal 9
10 Runtime error 115 ms 262144 KB Execution killed with signal 9
11 Runtime error 111 ms 262144 KB Execution killed with signal 9
12 Runtime error 110 ms 262144 KB Execution killed with signal 9
13 Runtime error 109 ms 262144 KB Execution killed with signal 9
14 Runtime error 110 ms 262144 KB Execution killed with signal 9
15 Runtime error 118 ms 262144 KB Execution killed with signal 9
16 Runtime error 124 ms 262144 KB Execution killed with signal 9
17 Runtime error 106 ms 262144 KB Execution killed with signal 9
18 Runtime error 121 ms 262144 KB Execution killed with signal 9
# Verdict Execution time Memory Grader output
1 Runtime error 113 ms 262144 KB Execution killed with signal 9
2 Runtime error 114 ms 262144 KB Execution killed with signal 9
3 Runtime error 113 ms 262144 KB Execution killed with signal 9
4 Runtime error 112 ms 262144 KB Execution killed with signal 9
5 Runtime error 122 ms 262144 KB Execution killed with signal 9
6 Runtime error 109 ms 262144 KB Execution killed with signal 9
7 Runtime error 131 ms 262144 KB Execution killed with signal 9
8 Runtime error 128 ms 262144 KB Execution killed with signal 9
9 Runtime error 138 ms 262144 KB Execution killed with signal 9
10 Runtime error 110 ms 262144 KB Execution killed with signal 9
11 Runtime error 108 ms 262144 KB Execution killed with signal 9
12 Runtime error 115 ms 262144 KB Execution killed with signal 9
13 Runtime error 111 ms 262144 KB Execution killed with signal 9
14 Runtime error 107 ms 262144 KB Execution killed with signal 9
15 Runtime error 113 ms 262144 KB Execution killed with signal 9
16 Runtime error 109 ms 262144 KB Execution killed with signal 9
17 Runtime error 111 ms 262144 KB Execution killed with signal 9
18 Runtime error 103 ms 262144 KB Execution killed with signal 9
19 Runtime error 101 ms 262144 KB Execution killed with signal 9
20 Runtime error 110 ms 262144 KB Execution killed with signal 9
21 Runtime error 108 ms 262144 KB Execution killed with signal 9
22 Runtime error 112 ms 262144 KB Execution killed with signal 9
23 Runtime error 113 ms 262144 KB Execution killed with signal 9
24 Runtime error 104 ms 262144 KB Execution killed with signal 9
25 Runtime error 108 ms 262144 KB Execution killed with signal 9
26 Runtime error 121 ms 262144 KB Execution killed with signal 9
27 Runtime error 115 ms 262144 KB Execution killed with signal 9
28 Runtime error 104 ms 262144 KB Execution killed with signal 9
29 Runtime error 120 ms 262144 KB Execution killed with signal 9
30 Runtime error 125 ms 262144 KB Execution killed with signal 9
31 Runtime error 109 ms 262144 KB Execution killed with signal 9
32 Runtime error 113 ms 262144 KB Execution killed with signal 9
33 Runtime error 129 ms 262144 KB Execution killed with signal 9
34 Runtime error 131 ms 262144 KB Execution killed with signal 9
35 Runtime error 114 ms 262144 KB Execution killed with signal 9
36 Runtime error 114 ms 262144 KB Execution killed with signal 9
37 Runtime error 123 ms 262144 KB Execution killed with signal 9
38 Runtime error 134 ms 262144 KB Execution killed with signal 9
39 Runtime error 117 ms 262144 KB Execution killed with signal 9
40 Runtime error 110 ms 262144 KB Execution killed with signal 9
41 Runtime error 120 ms 262144 KB Execution killed with signal 9
42 Runtime error 111 ms 262144 KB Execution killed with signal 9