QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#239252 | #6558. Allergen Testing | Fyind# | TL | 0ms | 3648kb | C++17 | 1.1kb | 2023-11-04 19:26:05 | 2023-11-04 19:26:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define _ <<" "<<
#define sz(x) ((int) (x).size())
typedef pair<int, int> pii;
typedef long long ll;
const int maxn = 5e5 + 5;
ll c[66][66];
ll f(ll n, ll x) {
if (x > 63 || (1ll<<x) >= n) return 1;
if (n > 2 && x == 1) return LLONG_MAX;
ll sum = 1;
ll ret = LLONG_MAX;
for (int k = 1;k <= x; ++k) {
sum += c[x][k];
if (n % sum == 0) ret = min(ret, f(n/sum, x-k));
else if (n - n/sum * (sum-1) == n/sum + 1) ret = min(ret, f(n/sum,x-k));
else ret = min(ret, f((n+sum-1)/sum, x-k));
}
return ret;
}
ll n, d;
void run_case() {
cin >> n >> d;
for (int x = 1;x; ++x) if (f(n,x) <= d) {
cout << x << '\n';
return;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
c[0][0] = 1;
for (int i = 1;i <= 64; ++i) {
c[i][0] = 1;
for (int j = 1;j <= 64; ++j) {
c[i][j] = c[i-1][j-1] + c[i-1][j];
}
}
int T; cin >> T;
while (T--) run_case();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
input:
1 4 1
output:
2
result:
ok single line: '2'
Test #2:
score: -100
Time Limit Exceeded
input:
10000 1 1 1000000000000000000 1 1 1000000000000000000 1000000000000000000 1000000000000000000 26615519354743225 163142634 26615519354743225 163142634 26615519354743224 163142634 26615519354743226 163142634 847997831064072529 920867976 847997831064072529 920867976 847997831064072528 920867976 8479978...