QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#239252#6558. Allergen TestingFyind#TL 0ms3648kbC++171.1kb2023-11-04 19:26:052023-11-04 19:26:05

Judging History

你现在查看的是最新测评结果

  • [2023-11-04 19:26:05]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3648kb
  • [2023-11-04 19:26:05]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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...

output:


result: