Submission #493814

# Submission time Handle Problem Language Result Execution time Memory
493814 2021-12-13T03:51:16 Z goodluck2020 Brunhilda’s Birthday (BOI13_brunhilda) C++14
77.4603 / 100
237 ms 81060 KB
#include <bits/stdc++.h>
#define task "brunhilda"

using namespace std;
const int N = 1e5 + 5;
const int M = 1e7;
int m, q, A[N], Q[N];
namespace sub1
{
    int dp[N];
    void solve()
    {
        for(int i = 1; i <= 1e4; i++) dp[i] = 1e9;
        for(int i = 1; i <= 1e4; i++)
            for(int j = 1; j <= m; j++)
            dp[i] = min(dp[i], dp[i - i % A[j]] + 1);
        for(int i = 1; i <= q; i++)
        {
            if(dp[Q[i]] == 1e9) cout << "oo" << '\n';
            else cout << dp[Q[i]] << '\n';
        }
    }
}
namespace sub2
{
    int greed[M + 5], dp[M + 5];
    long long lcm = 1;
    void solve()
    {
        for(int i = 1; i <= m; i++)
            lcm = min((long long)1e8,lcm * A[i]);
        for(int i = 1; i <= m; i++)
            for(int j = A[i] - 1; j <= M; j += A[i])
                greed[j] = A[i] - 1;
        for(int i = M; i >= 1; i--)
            greed[i] = max(greed[i], greed[i + 1] - 1);
        for(int i = 1; i <= M; i++)
            dp[i] = dp[i - greed[i]] + 1;
        for(int i = 1; i <= q; i++)
        if(Q[i] >= lcm) cout << "oo" << '\n';
        else cout << dp[Q[i]] << '\n';
    }
}
int main()
{
    if(fopen(task ".inp","r"))
    {
        freopen(task ".inp","r",stdin);
        freopen(task ".out","w",stdout);
    }
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> m >> q;
    int maxN = 0;
    for(int i = 1; i <= m; i++) cin >> A[i];
    for(int i = 1; i <= q; i++) cin >> Q[i], maxN = max(maxN, Q[i]);
    if(m <= 1e4 && q <= 1e4 && maxN <= 1e4) sub1::solve();
    else sub2::solve();
}

Compilation message

brunhilda.cpp: In function 'int main()':
brunhilda.cpp:48:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
brunhilda.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen(task ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 6 ms 456 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 5 ms 332 KB Output is correct
13 Correct 49 ms 332 KB Output is correct
14 Correct 50 ms 452 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 3 ms 332 KB Output is correct
17 Correct 4 ms 460 KB Output is correct
18 Correct 5 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 78644 KB Output is correct
2 Correct 95 ms 79556 KB Output is correct
3 Correct 196 ms 79244 KB Output is correct
4 Correct 98 ms 78508 KB Output is correct
5 Correct 143 ms 79192 KB Output is correct
6 Correct 91 ms 78508 KB Output is correct
7 Correct 89 ms 78660 KB Output is correct
8 Correct 100 ms 78532 KB Output is correct
9 Correct 166 ms 79300 KB Output is correct
10 Correct 200 ms 79312 KB Output is correct
11 Incorrect 199 ms 78920 KB Output isn't correct
12 Correct 123 ms 78536 KB Output is correct
13 Correct 82 ms 78580 KB Output is correct
14 Correct 98 ms 78544 KB Output is correct
15 Correct 163 ms 78944 KB Output is correct
16 Correct 101 ms 79684 KB Output is correct
17 Correct 175 ms 78524 KB Output is correct
18 Correct 165 ms 79620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 180 ms 79684 KB Output is correct
2 Correct 219 ms 79460 KB Output is correct
3 Correct 203 ms 79940 KB Output is correct
4 Incorrect 142 ms 79836 KB Output isn't correct
5 Incorrect 114 ms 81060 KB Output isn't correct
6 Correct 178 ms 79908 KB Output is correct
7 Correct 157 ms 80380 KB Output is correct
8 Correct 179 ms 79652 KB Output is correct
9 Correct 171 ms 79580 KB Output is correct
10 Correct 142 ms 78704 KB Output is correct
11 Incorrect 126 ms 78920 KB Output isn't correct
12 Correct 160 ms 78864 KB Output is correct
13 Correct 197 ms 80236 KB Output is correct
14 Correct 135 ms 80244 KB Output is correct
15 Incorrect 168 ms 78984 KB Output isn't correct
16 Correct 185 ms 78916 KB Output is correct
17 Correct 160 ms 79116 KB Output is correct
18 Correct 208 ms 79420 KB Output is correct
19 Incorrect 95 ms 78928 KB Output isn't correct
20 Correct 209 ms 79920 KB Output is correct
21 Incorrect 151 ms 80324 KB Output isn't correct
22 Correct 237 ms 81024 KB Output is correct
23 Correct 120 ms 80232 KB Output is correct
24 Correct 105 ms 79940 KB Output is correct
25 Incorrect 153 ms 80000 KB Output isn't correct
26 Incorrect 158 ms 79804 KB Output isn't correct
27 Correct 220 ms 80308 KB Output is correct
28 Incorrect 114 ms 80048 KB Output isn't correct
29 Correct 215 ms 81008 KB Output is correct
30 Correct 190 ms 80708 KB Output is correct
31 Correct 118 ms 79756 KB Output is correct
32 Incorrect 128 ms 79940 KB Output isn't correct
33 Incorrect 101 ms 79820 KB Output isn't correct
34 Correct 155 ms 80380 KB Output is correct
35 Incorrect 105 ms 80044 KB Output isn't correct
36 Correct 208 ms 80832 KB Output is correct
37 Incorrect 115 ms 81052 KB Output isn't correct
38 Correct 178 ms 79924 KB Output is correct
39 Incorrect 107 ms 79940 KB Output isn't correct
40 Correct 159 ms 79912 KB Output is correct
41 Correct 145 ms 80520 KB Output is correct
42 Incorrect 187 ms 80080 KB Output isn't correct