Given an array with N elements and a number P (P ≤ N). Pick randomly P elements from the array, let's call T the product of these elements. Find the largest x that T % 10^x = 0
Example:
Input
3 2
26 5 96
Output
1
Input
3 2
25 4 90
Output
2
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Given an array with N elements and a number P (P ≤ N). Pick randomly P elements from the array, let's call T the product of these elements. Find the largest x that T % 10^x = 0
Example:
Input
3 2
26 5 96
Output
1
Input
3 2
25 4 90
Output
2
Название |
---|
Sorry if i have some mistakes, i know english not well.
So. Main condition (T % 10^x == 0) Makes it clear that we need only 5 and 2 in decomposition of a number. We can write dp[i][j][k]. where i — how many 2 are in the decomposition of our K number, which we are choose and j — how many 5 in our decomposition. i, j are <= log5(maxA[i]) * n. And k <= n.
O(n^3 * log5(maxA[i])^2) I think it possible to solve better
https://codeforces.net/contest/837/problem/D
This is almost exactly the same problem but here you're restricted to choosing a subset of size k.