|
| 1 | + |
| 2 | +/* |
| 3 | +problem: http://codeforces.com/contest/837/problem/D |
| 4 | +*/ |
| 5 | + |
| 6 | +#include<bits/stdc++.h> //g++ -std=c++11 |
| 7 | +using namespace std; |
| 8 | + |
| 9 | +//#define DEBUG |
| 10 | +#ifndef DEBUG |
| 11 | + #define din if(0) cin |
| 12 | + #define dout if(0) cout |
| 13 | +#else |
| 14 | + #define din cin |
| 15 | + #define dout cout |
| 16 | +#endif |
| 17 | + |
| 18 | + |
| 19 | +#define inf (1 << 30) |
| 20 | +#define pi (2*asin(1)) |
| 21 | +#define repall(it,A) for(typeof A.begin() it = A.begin(); it!=A.end(); it++) |
| 22 | +#define rep(i,x,y) for (int i = x; i < y; i++) |
| 23 | +#define irep(i,x,y) for (int i = x; i >= y; i--) |
| 24 | +#define clr(A,x) memset(A, x, sizeof A) |
| 25 | +#define pb push_back |
| 26 | +#define mp make_pair |
| 27 | +#define MAX 5205 |
| 28 | + |
| 29 | +typedef vector < int > vi; |
| 30 | +typedef pair < int , int > pii; |
| 31 | +typedef vector < pii > vii; |
| 32 | +typedef long long int i64; |
| 33 | +typedef vector < i64 > vi64; |
| 34 | +int dp[2][205][MAX]; |
| 35 | +int n, k, two[205], five[205]; |
| 36 | +int totFive = 0 ; |
| 37 | +void toNum(i64 x, int i){ |
| 38 | + two[i] = five[i] = 0; |
| 39 | + while(x % 2ll == 0){ |
| 40 | + two[i]++; |
| 41 | + x /= 2ll; |
| 42 | + } |
| 43 | + while(x % 5ll == 0){ |
| 44 | + five[i]++; |
| 45 | + x /= 5ll; |
| 46 | + } |
| 47 | + totFive += five[i]; |
| 48 | +} |
| 49 | +int main() |
| 50 | +{ |
| 51 | + scanf("%d %d", &n, &k); |
| 52 | + rep(i, 0, n){ |
| 53 | + i64 x; |
| 54 | + cin >> x; |
| 55 | + toNum(x, i); |
| 56 | + } |
| 57 | + rep(j, 0, k + 1) rep(l, 0, totFive + 1) dp[0][j][l] = dp[1][j][l] = -inf; |
| 58 | + dp[0][0][0] = dp[1][0][0] = 0; |
| 59 | + rep(num, 0, n){ |
| 60 | + int i = (num % 2); |
| 61 | + int i_n = i xor 1; |
| 62 | + |
| 63 | + rep(j, 0, k + 1){ |
| 64 | + rep(l, 0, totFive + 1){ |
| 65 | + dp[i_n][j][l] = dp[i][j][l]; |
| 66 | + if (l - five[num] >= 0 && j > 0) |
| 67 | + dp[i_n][j][l] = max(dp[i_n][j][l], dp[i][j - 1][l - five[num]] + two[num]); |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + int ans = 0; |
| 72 | + rep(l, 0, totFive + 1) ans = max(ans, min(l, dp[n%2][k][l])); |
| 73 | + printf("%d\n", ans); |
| 74 | +} |
| 75 | + |
0 commit comments