import java.io.*; import java.util.*;
class biscuits {
static HashMap<Long, Long> dp;
public static long count_tastiness(long x, long[] a){
int k=a.length;
dp=new HashMap<>();
dp.put((long)0,(long)0);
dp.put((long)1,(long)1);
//psa is bounded by 10^{18}
long[] psa=new long[61];
psa[0]=a[0];
for (int i = 1; i <k; i++) {
psa[i]=psa[i-1]+((long)a[i]<<i);
}
for (int i = k; i < 61; i++) {
psa[i]=psa[i-1];
}
for (int i = 1; i <=60; i++) {
comp((long)1<<i,psa,x);
}
return dp.get((long)1<<60);
}
public static void comp(long n, long[] psa, long x){
if(dp.get(n)==null){
int i=0;
long p=1;
while(p<n){
p*=2; i++;
}
p/=2; i--;
long ans=dp.get(p);
long min=Math.max(0,Math.min((long)n-p,(long) 1+psa[i]/x-p));
comp(min,psa,x);
ans+=dp.get(min);
dp.put(n, ans);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
10736 KB |
Output is correct |
2 |
Correct |
99 ms |
10744 KB |
Output is correct |
3 |
Correct |
108 ms |
10852 KB |
Output is correct |
4 |
Correct |
108 ms |
10508 KB |
Output is correct |
5 |
Correct |
103 ms |
10652 KB |
Output is correct |
6 |
Correct |
107 ms |
11128 KB |
Output is correct |
7 |
Correct |
99 ms |
10616 KB |
Output is correct |
8 |
Correct |
100 ms |
10620 KB |
Output is correct |
9 |
Correct |
99 ms |
10856 KB |
Output is correct |
10 |
Correct |
100 ms |
10744 KB |
Output is correct |
11 |
Correct |
98 ms |
10716 KB |
Output is correct |
12 |
Correct |
100 ms |
10912 KB |
Output is correct |
13 |
Correct |
109 ms |
10992 KB |
Output is correct |
14 |
Correct |
103 ms |
11256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
10488 KB |
Output is correct |
2 |
Correct |
96 ms |
10788 KB |
Output is correct |
3 |
Correct |
112 ms |
11236 KB |
Output is correct |
4 |
Correct |
119 ms |
11996 KB |
Output is correct |
5 |
Correct |
115 ms |
11504 KB |
Output is correct |
6 |
Correct |
111 ms |
11512 KB |
Output is correct |
7 |
Correct |
115 ms |
11652 KB |
Output is correct |
8 |
Correct |
104 ms |
11252 KB |
Output is correct |
9 |
Correct |
108 ms |
11120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
10744 KB |
Output is correct |
2 |
Correct |
101 ms |
11196 KB |
Output is correct |
3 |
Correct |
108 ms |
11616 KB |
Output is correct |
4 |
Correct |
109 ms |
11496 KB |
Output is correct |
5 |
Correct |
113 ms |
11096 KB |
Output is correct |
6 |
Correct |
113 ms |
11616 KB |
Output is correct |
7 |
Correct |
109 ms |
11464 KB |
Output is correct |
8 |
Correct |
109 ms |
11512 KB |
Output is correct |
9 |
Correct |
107 ms |
10932 KB |
Output is correct |
10 |
Correct |
118 ms |
12516 KB |
Output is correct |
11 |
Correct |
125 ms |
13312 KB |
Output is correct |
12 |
Correct |
126 ms |
13936 KB |
Output is correct |
13 |
Correct |
120 ms |
13412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
485 ms |
39700 KB |
Output is correct |
2 |
Correct |
639 ms |
47904 KB |
Output is correct |
3 |
Correct |
594 ms |
47920 KB |
Output is correct |
4 |
Correct |
608 ms |
47448 KB |
Output is correct |
5 |
Correct |
506 ms |
44788 KB |
Output is correct |
6 |
Correct |
503 ms |
47596 KB |
Output is correct |
7 |
Correct |
485 ms |
48412 KB |
Output is correct |
8 |
Correct |
503 ms |
46560 KB |
Output is correct |
9 |
Correct |
469 ms |
47284 KB |
Output is correct |
10 |
Correct |
507 ms |
44728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
10736 KB |
Output is correct |
2 |
Correct |
99 ms |
10744 KB |
Output is correct |
3 |
Correct |
108 ms |
10852 KB |
Output is correct |
4 |
Correct |
108 ms |
10508 KB |
Output is correct |
5 |
Correct |
103 ms |
10652 KB |
Output is correct |
6 |
Correct |
107 ms |
11128 KB |
Output is correct |
7 |
Correct |
99 ms |
10616 KB |
Output is correct |
8 |
Correct |
100 ms |
10620 KB |
Output is correct |
9 |
Correct |
99 ms |
10856 KB |
Output is correct |
10 |
Correct |
100 ms |
10744 KB |
Output is correct |
11 |
Correct |
98 ms |
10716 KB |
Output is correct |
12 |
Correct |
100 ms |
10912 KB |
Output is correct |
13 |
Correct |
109 ms |
10992 KB |
Output is correct |
14 |
Correct |
103 ms |
11256 KB |
Output is correct |
15 |
Correct |
97 ms |
10488 KB |
Output is correct |
16 |
Correct |
96 ms |
10788 KB |
Output is correct |
17 |
Correct |
112 ms |
11236 KB |
Output is correct |
18 |
Correct |
119 ms |
11996 KB |
Output is correct |
19 |
Correct |
115 ms |
11504 KB |
Output is correct |
20 |
Correct |
111 ms |
11512 KB |
Output is correct |
21 |
Correct |
115 ms |
11652 KB |
Output is correct |
22 |
Correct |
104 ms |
11252 KB |
Output is correct |
23 |
Correct |
108 ms |
11120 KB |
Output is correct |
24 |
Correct |
105 ms |
10744 KB |
Output is correct |
25 |
Correct |
101 ms |
11196 KB |
Output is correct |
26 |
Correct |
108 ms |
11616 KB |
Output is correct |
27 |
Correct |
109 ms |
11496 KB |
Output is correct |
28 |
Correct |
113 ms |
11096 KB |
Output is correct |
29 |
Correct |
113 ms |
11616 KB |
Output is correct |
30 |
Correct |
109 ms |
11464 KB |
Output is correct |
31 |
Correct |
109 ms |
11512 KB |
Output is correct |
32 |
Correct |
107 ms |
10932 KB |
Output is correct |
33 |
Correct |
118 ms |
12516 KB |
Output is correct |
34 |
Correct |
125 ms |
13312 KB |
Output is correct |
35 |
Correct |
126 ms |
13936 KB |
Output is correct |
36 |
Correct |
120 ms |
13412 KB |
Output is correct |
37 |
Correct |
485 ms |
39700 KB |
Output is correct |
38 |
Correct |
639 ms |
47904 KB |
Output is correct |
39 |
Correct |
594 ms |
47920 KB |
Output is correct |
40 |
Correct |
608 ms |
47448 KB |
Output is correct |
41 |
Correct |
506 ms |
44788 KB |
Output is correct |
42 |
Correct |
503 ms |
47596 KB |
Output is correct |
43 |
Correct |
485 ms |
48412 KB |
Output is correct |
44 |
Correct |
503 ms |
46560 KB |
Output is correct |
45 |
Correct |
469 ms |
47284 KB |
Output is correct |
46 |
Correct |
507 ms |
44728 KB |
Output is correct |
47 |
Correct |
498 ms |
42220 KB |
Output is correct |
48 |
Correct |
566 ms |
47312 KB |
Output is correct |
49 |
Correct |
533 ms |
44408 KB |
Output is correct |
50 |
Correct |
581 ms |
47124 KB |
Output is correct |
51 |
Correct |
488 ms |
36776 KB |
Output is correct |
52 |
Correct |
499 ms |
37124 KB |
Output is correct |
53 |
Correct |
420 ms |
36188 KB |
Output is correct |
54 |
Correct |
863 ms |
66080 KB |
Output is correct |
55 |
Correct |
660 ms |
58784 KB |
Output is correct |
56 |
Correct |
651 ms |
63632 KB |
Output is correct |
57 |
Correct |
614 ms |
63096 KB |
Output is correct |