QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#290356#6558. Allergen TestingakshaykhandelwalWA 24ms293848kbC++203.2kb2023-12-24 21:24:592023-12-24 21:24:59

Judging History

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

  • [2023-12-24 21:24:59]
  • 评测
  • 测评结果:WA
  • 用时:24ms
  • 内存:293848kb
  • [2023-12-24 21:24:59]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

// matrix multiplication
vector<vector<__int128>> matmul(vector<vector<__int128>> &a, vector<vector<__int128>> &b){
    int n = (int)a.size(), m = (int)a[0].size(), l = (int)b[0].size();
    vector<vector<__int128>> ret(n, vector<__int128>());
    for (int i = 0; i < n; i++){
        for (int j = 0; j < l; j++){
            __int128 ths = 0;
            for (int k = 0; k < m; k++){
                ths += a[i][k] * b[k][j];
            }
            ret[i].push_back(ths);
        }
    }

    return ret;
}

vector<vector<__int128>> matexp(vector<vector<__int128>> &mat, long long k){
    int n = (int)mat.size();
    if (k == 0){
        vector<vector<__int128>> id(n, vector<__int128>());
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                id[i].push_back(0);
            }
            id[i][i] = 1;
        }
        return id;
    }
    else if (k%2){
        vector<vector<__int128>> w = matexp(mat, k - 1);
        return matmul(w, mat);
    }
    else{
        vector<vector<__int128>> w = matexp(mat, k/2);
        return matmul(w, w);
    }
}

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

    long long x = 60, d = 300000;
    vector<vector<__int128>> dp(x + 1, vector<__int128>(d + 1, 0));
    vector<vector<__int128>> c(x + 1, vector<__int128>(x + 1, 0));
    c[0][0] = 1;
    for (int i = 0; i <= d; i++) dp[0][i] = 1;

    __int128 lim = 2e18;

    long long p = 1;
    int req = d;
    for (int i = 1; i <= x; i++) {
        c[i][0] = 1;
        for (int j = 1; j <= x; j++) {
            c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
        }

        p *= 2;
        dp[i][1] = p;
        for (int j = 2; j <= req; j++) {
            for (int y = 0; y <= i; y++) {
                dp[i][j] += dp[i - y][j - 1] * c[i][y];
            }
        }
        int n_req = 0;
        for (int j = 1; j <= req; j++) {
            if (dp[i][j] >= lim) {
                n_req = j;
                break;
            }
        }
        req = n_req;
    }

    int t;
    cin >> t;

    while (t--) {
        long long n, dd;
        cin >> n >> dd;

        if (n == 1) {
            cout << 0 << '\n';
            continue;
        }

        if (dd <= d) {
            for (long long i = 1; i <= x; i++) {
                if (dp[i][dd] >= n) {
                    cout << i << '\n';
                    break;
                }
            }
        }
        else {
            vector<vector<__int128>> v = {{1}, {2}, {4}, {8}};
            vector<vector<__int128>> mat = {{1, 0, 0, 0}, {1, 1, 0, 0}, {1, 2, 1, 0}, {1, 3, 3, 1}};
            mat = matexp(mat, dd - 1);
            v = matmul(mat, v);

            if (v[1][0] >= n) {
                cout << 1 << '\n';
                continue;
            }
            if (v[2][0] >= n) {
                cout << 2 << '\n';
                continue;
            }
            if (v[3][0] >= n) {
                cout << 3 << '\n';
                continue;
            }

            cout << 4 << '\n';
        }
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 24ms
memory: 293848kb

input:

1
4 1

output:

2

result:

ok single line: '2'

Test #2:

score: -100
Wrong Answer
time: 20ms
memory: 293684kb

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:

0
60
0
1
2
2
2
3
2
2
2
3
2
2
2
3
2
2
2
3
2
2
2
3
2
2
2
3
2
2
2
3
2
2
2
3
2
2
2
3
2
2
2
3
3
3
3
4
3
3
3
4
3
3
3
4
3
3
3
4
3
3
3
4
3
3
3
4
3
3
3
4
3
3
3
4
13
13
13
14
14
14
14
15
16
16
16
17
17
17
17
18
19
19
19
20
21
21
21
22
22
22
22
23
24
24
24
25
25
25
25
26
26
26
26
27
27
27
27
28
28
28
28
29
29
...

result:

wrong answer 77th lines differ - expected: '3', found: '13'