#include <cmath> #include <cstring> #include <iostream> #include <vector> using namespace std; vector<int> p; typedef unsigned long long ull; ull N; int k; vector<int> w; const int C = 7 * (1 << 17); ull a[C]; ull best = 0; void ks() { memset(a, 0, sizeof(a)); a[0] = -1; for(int i=0; i<k; i++) for(int r=0; r<w[i]; r++) { ull mark=0; for(int j=r; j<C; j+=w[i]) if(mark) a[j]|=1ULL<<i; else mark|=a[j]; } } void construct(int j, int i, ull c) { if(i==0) { if(c<=N) best=max(c, best); return; } for(; j>=0; j--) if(a[i]&(1ULL<<j)) construct(j, i - w[j], c * p[j]); } void find(int i) { if(a[i]) construct(k-1, i, 1); } int main() { cin >> k >> N; p.resize(k); for(int i=0; i<k; i++) cin >> p[i]; // scale * log(N) = C - 64 double scale = (C - 64) / log(N); w.resize(k); for(int i=0;i<k;i++) w[i] = round(scale * log(p[i])); ks(); int x=C-1; while(a[x]==0) x--; int y=0; for(int i=x; i>=y; i--) { find(i); if(best && y==0) y=i-32; } cout << best << endl; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #include <cmath> #include <cstring> #include <iostream> #include <vector> using namespace std; vector<int> p; typedef unsigned long long ull; ull N; int k; vector<int> w; const int C = 7 * (1 << 17); ull a[C]; ull best = 0; void ks() { memset(a, 0, sizeof(a)); a[0] = -1; for(int i=0; i<k; i++) for(int r=0; r<w[i]; r++) { ull mark=0; for(int j=r; j<C; j+=w[i]) if(mark) a[j]|=1ULL<<i; else mark|=a[j]; } } void construct(int j, int i, ull c) { if(i==0) { if(c<=N) best=max(c, best); return; } for(; j>=0; j--) if(a[i]&(1ULL<<j)) construct(j, i - w[j], c * p[j]); } void find(int i) { if(a[i]) construct(k-1, i, 1); } int main() { cin >> k >> N; p.resize(k); for(int i=0; i<k; i++) cin >> p[i]; // scale * log(N) = C - 64 double scale = (C - 64) / log(N); w.resize(k); for(int i=0;i<k;i++) w[i] = round(scale * log(p[i])); ks(); int x=C-1; while(a[x]==0) x--; int y=0; for(int i=x; i>=y; i--) { find(i); if(best && y==0) y=i-32; } cout << best << endl; } |