Submission #732957

# Submission time Handle Problem Language Result Execution time Memory
732957 2023-04-29T19:54:43 Z PoonYaPat Packing Biscuits (IOI20_biscuits) C++14
100 / 100
70 ms 1336 KB
#include "biscuits.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll qs[60],sum[60],bag;

ll find(ll x) {
    if (x<0) return 0;
    if (x==0) return 1;
    if (x==1) return qs[0];

    int k;
    for (int i=59; i>0; --i) {
        if ((1ll<<i)<=x) {
            k=i;
            break;
        }
    }
    return qs[k-1]+find(min(x-(1ll<<k),(sum[k]/bag)-(1ll<<k)));
}

ll count_tastiness(ll X, vector<ll> a) {
    bag=X;
    sum[0]=a[0];
    if (a[0]>=bag) qs[0]=2;
    else qs[0]=1;

    for (int i=1; i<60; ++i) {
        if (i<a.size()) sum[i]=sum[i-1]+(1ll<<i)*a[i];
        else sum[i]=sum[i-1];
        qs[i]=find((1ll<<(i+1))-1);
    }

    return qs[59];
}

Compilation message

biscuits.cpp: In function 'll count_tastiness(ll, std::vector<long long int>)':
biscuits.cpp:30:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         if (i<a.size()) sum[i]=sum[i-1]+(1ll<<i)*a[i];
      |             ~^~~~~~~~~
biscuits.cpp: In function 'll find(ll)':
biscuits.cpp:20:57: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
   20 |     return qs[k-1]+find(min(x-(1ll<<k),(sum[k]/bag)-(1ll<<k)));
      |                                                     ~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 340 KB Output is correct
2 Correct 18 ms 820 KB Output is correct
3 Correct 15 ms 1108 KB Output is correct
4 Correct 17 ms 1200 KB Output is correct
5 Correct 14 ms 1108 KB Output is correct
6 Correct 12 ms 1112 KB Output is correct
7 Correct 13 ms 1084 KB Output is correct
8 Correct 13 ms 1080 KB Output is correct
9 Correct 13 ms 1108 KB Output is correct
10 Correct 14 ms 1076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 304 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 304 KB Output is correct
31 Correct 1 ms 300 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 300 KB Output is correct
36 Correct 1 ms 296 KB Output is correct
37 Correct 10 ms 340 KB Output is correct
38 Correct 18 ms 820 KB Output is correct
39 Correct 15 ms 1108 KB Output is correct
40 Correct 17 ms 1200 KB Output is correct
41 Correct 14 ms 1108 KB Output is correct
42 Correct 12 ms 1112 KB Output is correct
43 Correct 13 ms 1084 KB Output is correct
44 Correct 13 ms 1080 KB Output is correct
45 Correct 13 ms 1108 KB Output is correct
46 Correct 14 ms 1076 KB Output is correct
47 Correct 20 ms 340 KB Output is correct
48 Correct 70 ms 1312 KB Output is correct
49 Correct 44 ms 404 KB Output is correct
50 Correct 70 ms 1132 KB Output is correct
51 Correct 14 ms 1336 KB Output is correct
52 Correct 4 ms 340 KB Output is correct
53 Correct 9 ms 1108 KB Output is correct
54 Correct 29 ms 1076 KB Output is correct
55 Correct 27 ms 1176 KB Output is correct
56 Correct 30 ms 1120 KB Output is correct
57 Correct 20 ms 1204 KB Output is correct