ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#208014 | #3712. Seeker Temple | 1024i | 100 | 2239ms | 12408kb | C++11 | 1.8kb | 2024-08-01 11:40:36 | 2024-08-01 12:43:57 |
answer
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#define ll long long
#define MAX_N 3000005
#define MAX_M 45
using namespace std;
ll n, k, factors[MAX_M], partialProducts[MAX_N], totalCount = 0, results[MAX_N], resultCount = 0;
ll MAX_LIMIT = 1e18;
void generateSubsets(int index, bool isOdd, ll currentProduct) {
if (isOdd) {
results[++resultCount] = currentProduct;
} else {
partialProducts[++totalCount] = currentProduct;
}
if (index > n) {
return;
}
for (ll i = 1;; i *= factors[index]) {
if (MAX_LIMIT / i < currentProduct) break;
generateSubsets(index + 2, isOdd, currentProduct * i);
}
}
bool canAchieveKthSmallestProduct(ll mid) {
ll left = 1, right = resultCount, sum = 0;
while (left <= totalCount) {
while (results[right] > mid / partialProducts[left] && right >= 1) right--;
sum += right;
left++;
}
return sum >= k;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> factors[i];
}
sort(factors + 1, factors + n + 1);
cin >> k;
generateSubsets(1, false, 1);
generateSubsets(2, true, 1);
sort(partialProducts + 1, partialProducts + totalCount + 1);
sort(results + 1, results + resultCount + 1);
totalCount = unique(partialProducts + 1, partialProducts + totalCount + 1) - partialProducts - 1;
resultCount = unique(results + 1, results + resultCount + 1) - results - 1;
ll left = 0, right = 1e18;
while (left < right) {
ll mid = (left + right) / 2;
if (canAchieveKthSmallestProduct(mid)) {
right = mid;
} else {
left = mid + 1;
}
}
cout << right;
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 336ms
memory: 8984kb
input:
16 2 5 7 17 23 29 31 41 43 47 59 61 67 71 89 97 4177
output:
185150
result:
ok 1 number(s): "185150"
Test #2:
score: 10
Accepted
time: 105ms
memory: 4016kb
input:
16 5 13 17 19 23 37 41 43 53 59 61 67 71 73 83 97 1136
output:
152693
result:
ok 1 number(s): "152693"
Test #3:
score: 10
Accepted
time: 361ms
memory: 9064kb
input:
15 2 5 7 11 13 29 31 37 47 53 59 61 71 79 89 27760
output:
9506336
result:
ok 1 number(s): "9506336"
Test #4:
score: 10
Accepted
time: 198ms
memory: 6416kb
input:
16 3 7 11 17 19 23 29 37 41 43 59 61 67 71 79 83 15513
output:
9046527
result:
ok 1 number(s): "9046527"
Test #5:
score: 10
Accepted
time: 0ms
memory: 1248kb
input:
8 7 31 53 59 61 67 73 79 33053
output:
8263273940946857
result:
ok 1 number(s): "8263273940946857"
Test #6:
score: 10
Accepted
time: 0ms
memory: 1252kb
input:
8 13 29 37 41 47 61 73 79 66707
output:
904399311706295197
result:
ok 1 number(s): "904399311706295197"
Test #7:
score: 10
Accepted
time: 4ms
memory: 1276kb
input:
7 3 5 11 17 59 61 79 209466
output:
904010601099684375
result:
ok 1 number(s): "904010601099684375"
Test #8:
score: 10
Accepted
time: 408ms
memory: 10244kb
input:
15 2 3 5 7 13 19 29 43 59 71 73 79 83 89 97 140325038
output:
984828581062759296
result:
ok 1 number(s): "984828581062759296"
Test #9:
score: 10
Accepted
time: 315ms
memory: 8304kb
input:
16 2 5 7 17 19 41 43 47 53 59 61 67 73 79 83 89 79756884
output:
992695529294818384
result:
ok 1 number(s): "992695529294818384"
Test #10:
score: 10
Accepted
time: 512ms
memory: 12408kb
input:
15 2 3 5 7 11 17 23 29 43 47 59 73 79 83 89 198534643
output:
921655390703146000
result:
ok 1 number(s): "921655390703146000"