let's suppose the case:
k = 1, n = 1000;
arr[] = {1,3,5,7,9,11,..........1999]
For this case, the answer can be 2^N, and according to the question we have to return an integer. Is it possible?
Please help someone.
Thank you.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
let's suppose the case:
k = 1, n = 1000;
arr[] = {1,3,5,7,9,11,..........1999]
For this case, the answer can be 2^N, and according to the question we have to return an integer. Is it possible?
Please help someone.
Thank you.
Название |
---|
Group all the numbers which give same remainder with $$$k$$$
Can we take any 2 elements which belong to different groups?
Now we need to find ways to take elements of one group together in our subset. Think in terms of combinatorics and DP. Since the answer can be quite big we should be calculating wrt some mod
hint4: Read the issues mentioned in the blog first, rather than rushing to growing contribution.
Better to help someone than making useless comments. My comment posted above would help anyone who doesn't get how to approach this problem. I don't think like you so XD
Since n<=10^3 we can solve the problem in O(n^2) by the naive implementation of biginteger.
Yes, it is possible. $$$2^{1000}$$$, which is the largest possible answer, has roughly $$$300$$$ digits. Multiplying numbers to get to a $$$300$$$ digits number shouldn't be too slow. If you still get TLE, you can just represent bigInt using base $$$10^{9}$$$, which would bring the number of digits down to a laughable $$$34$$$. If you are using Python then time limit shouldn't be a problem as well, as Python has built-in Karatsuba multiplication algorithm, which is fast.
Multiplying $$$k$$$ numbers (polynomials) in the case when answer has $$$n$$$ digits is $$$O(n^2)$$$. One may prove it with a reasoning simar to the one behind $$$O(n^2)$$$ knapsack on trees.