Submission #923667

# Submission time Handle Problem Language Result Execution time Memory
923667 2024-02-07T14:41:24 Z sleepntsheep Brunhilda’s Birthday (BOI13_brunhilda) C++17
0 / 100
1000 ms 84060 KB
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#include <complex>

using namespace std;

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,tune=native")

#define ALL(x) begin(x), end(x)
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);

#if 1
#define M 100005
#define N 10000005
#else
#define M 20000
#define N 20000
#endif

int m, q, dp[N], p[M], yes[N];

multiset<int> ms;

int main()
{
    memset(dp, 63, sizeof dp);
    ShinLena;

    dp[0] = 0;
    cin >> m >> q;
    for (int i = 1; i <= m; ++i)
    {
        cin >> p[i];
        yes[p[i]] = 1;
    }

    auto factorize = [&](int n) {
        vector<int> f, nf;
        for (int d : {2, 3, 5}) {
            if (n % d == 0) {
                f.push_back(d);
                n /= d;
                while (n % d == 0) n /= d;
            }
        }


        static array<int, 8> increments = {4, 2, 4, 2, 4, 6, 2, 6};
        int i = 0;

        for (long long d = 7; d * d <= n; d += increments[i++]) {
            if (n % d == 0) {
                f.push_back(d);
                n /= d;
                while (n % d == 0) n /= d;
            }
            if (i == 8) i = 0;
        }

        if (n > 1) f.push_back(n);

        return f;
    };

    for (int i = 0; i < m; ++i) ms.insert(dp[0]);

    for (int i = 1; i < N; ++i)
    {
        auto F = factorize(i);
        for (auto x : F) if (yes[x])
            ms.erase(ms.find(dp[i-x]));

        if (ms.size())
            dp[i] = min(dp[i], *ms.begin() + 1);

        for (auto x : F) if (yes[x])
            ms.insert(dp[i]);
    }

    for (int x, i = 1; i <= q; ++i)
    {
        cin >> x;
        if (dp[x] > 1e9) cout << "oo\n";
        else cout << dp[x] << '\n';
    }


    return 0;
}


# Verdict Execution time Memory Grader output
1 Execution timed out 1052 ms 42016 KB Time limit exceeded
2 Execution timed out 1046 ms 42016 KB Time limit exceeded
3 Execution timed out 1035 ms 42000 KB Time limit exceeded
4 Execution timed out 1037 ms 42048 KB Time limit exceeded
5 Execution timed out 1054 ms 42016 KB Time limit exceeded
6 Execution timed out 1012 ms 42064 KB Time limit exceeded
7 Execution timed out 1079 ms 42000 KB Time limit exceeded
8 Execution timed out 1043 ms 42064 KB Time limit exceeded
9 Execution timed out 1070 ms 42004 KB Time limit exceeded
10 Execution timed out 1059 ms 42068 KB Time limit exceeded
11 Execution timed out 1043 ms 42064 KB Time limit exceeded
12 Execution timed out 1057 ms 41820 KB Time limit exceeded
13 Execution timed out 1046 ms 42100 KB Time limit exceeded
14 Execution timed out 1061 ms 42076 KB Time limit exceeded
15 Execution timed out 1032 ms 42020 KB Time limit exceeded
16 Execution timed out 1058 ms 42020 KB Time limit exceeded
17 Execution timed out 1050 ms 42024 KB Time limit exceeded
18 Execution timed out 1070 ms 42060 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1035 ms 46940 KB Time limit exceeded
2 Execution timed out 1035 ms 84056 KB Time limit exceeded
3 Execution timed out 1059 ms 52076 KB Time limit exceeded
4 Execution timed out 1008 ms 44644 KB Time limit exceeded
5 Execution timed out 1020 ms 51032 KB Time limit exceeded
6 Execution timed out 1051 ms 44536 KB Time limit exceeded
7 Execution timed out 1022 ms 46916 KB Time limit exceeded
8 Execution timed out 1014 ms 42176 KB Time limit exceeded
9 Execution timed out 1064 ms 52052 KB Time limit exceeded
10 Execution timed out 1057 ms 52088 KB Time limit exceeded
11 Execution timed out 1083 ms 48416 KB Time limit exceeded
12 Execution timed out 1098 ms 44592 KB Time limit exceeded
13 Execution timed out 1034 ms 44384 KB Time limit exceeded
14 Execution timed out 1058 ms 44644 KB Time limit exceeded
15 Execution timed out 1043 ms 48476 KB Time limit exceeded
16 Execution timed out 1072 ms 84060 KB Time limit exceeded
17 Execution timed out 1033 ms 44320 KB Time limit exceeded
18 Execution timed out 1078 ms 57680 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1018 ms 49112 KB Time limit exceeded
2 Execution timed out 1072 ms 49244 KB Time limit exceeded
3 Execution timed out 1061 ms 48988 KB Time limit exceeded
4 Execution timed out 1071 ms 44492 KB Time limit exceeded
5 Execution timed out 1039 ms 66316 KB Time limit exceeded
6 Execution timed out 1061 ms 45100 KB Time limit exceeded
7 Execution timed out 1071 ms 59996 KB Time limit exceeded
8 Execution timed out 1057 ms 48988 KB Time limit exceeded
9 Execution timed out 1020 ms 49116 KB Time limit exceeded
10 Execution timed out 1025 ms 44616 KB Time limit exceeded
11 Execution timed out 1050 ms 44560 KB Time limit exceeded
12 Execution timed out 1061 ms 44860 KB Time limit exceeded
13 Execution timed out 1043 ms 48052 KB Time limit exceeded
14 Execution timed out 1061 ms 42032 KB Time limit exceeded
15 Execution timed out 1099 ms 44376 KB Time limit exceeded
16 Execution timed out 1054 ms 44672 KB Time limit exceeded
17 Execution timed out 1093 ms 48796 KB Time limit exceeded
18 Execution timed out 1071 ms 49228 KB Time limit exceeded
19 Execution timed out 1069 ms 46876 KB Time limit exceeded
20 Execution timed out 1041 ms 49336 KB Time limit exceeded
21 Execution timed out 1058 ms 42276 KB Time limit exceeded
22 Execution timed out 1044 ms 53840 KB Time limit exceeded
23 Execution timed out 1038 ms 48056 KB Time limit exceeded
24 Execution timed out 1043 ms 44372 KB Time limit exceeded
25 Execution timed out 1031 ms 44376 KB Time limit exceeded
26 Execution timed out 1054 ms 44628 KB Time limit exceeded
27 Execution timed out 1062 ms 55800 KB Time limit exceeded
28 Execution timed out 1041 ms 44376 KB Time limit exceeded
29 Execution timed out 1048 ms 53844 KB Time limit exceeded
30 Execution timed out 1036 ms 50008 KB Time limit exceeded
31 Execution timed out 1039 ms 44804 KB Time limit exceeded
32 Execution timed out 1037 ms 44980 KB Time limit exceeded
33 Execution timed out 1055 ms 44300 KB Time limit exceeded
34 Execution timed out 1033 ms 59984 KB Time limit exceeded
35 Execution timed out 1030 ms 44120 KB Time limit exceeded
36 Execution timed out 1046 ms 53332 KB Time limit exceeded
37 Execution timed out 1070 ms 66132 KB Time limit exceeded
38 Execution timed out 1043 ms 44840 KB Time limit exceeded
39 Execution timed out 1010 ms 44384 KB Time limit exceeded
40 Execution timed out 1037 ms 44908 KB Time limit exceeded
41 Execution timed out 1031 ms 64084 KB Time limit exceeded
42 Execution timed out 1050 ms 44412 KB Time limit exceeded