QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#239266#6558. Allergen TestingFyind#TL 0ms3592kbC++171.3kb2023-11-04 19:35:462023-11-04 19:35:46

Judging History

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

  • [2023-11-04 19:35:46]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3592kb
  • [2023-11-04 19:35:46]
  • 提交

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;
const ll oo = LLONG_MAX/2;
ll c[66][66];

map<pair<ll,ll>,ll> ans;

ll f(ll n, ll x) {
    // cout << n _ x << endl;
    if (x > 63 || (1ll<<x) >= n) return 1;
    if (n > 2 && x == 1) return oo;
    if (ans[{n,x}]) return ans[{n,x}];
    ll sum = 1;
    ll ret = oo;
    for (int k = 1;k < x; ++k) {
        sum += c[x][k];
        if (n % sum == 0) ret = min(ret, f(n/sum, x-k) + 1);
        else if (n - n/sum * (sum-1) == n/sum + 1) ret = min(ret, f(n/sum,x-k) + 1);
        else ret = min(ret, f((n+sum-1)/sum, x-k) + 1);
    }
    ans[{n,x}] = ret;
    // cout << n _ x _ ret << endl;
    return ret;
}

ll n, d;

void run_case() {
    cin >> n >> d;
    for (int x = 1;x <= 64; ++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: 3592kb

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: