QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#290342#6558. Allergen TestingakshaykhandelwalWA 56ms293676kbC++202.5kb2023-12-24 20:59:572023-12-24 20:59:57

Judging History

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

  • [2023-12-24 20:59:57]
  • 评测
  • 测评结果:WA
  • 用时:56ms
  • 内存:293676kb
  • [2023-12-24 20:59:57]
  • 提交

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

    long long p = 1;
    for (int i = 1; i <= x; i++) {
        p *= 2;
        dp[i][1] = p;
        for (int j = 2; j <= d; j++) dp[i][j] = (p - 1) * dp[i - 1][j - 1] + dp[i][j - 1];
    }

    int t;
    cin >> t;

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

        if (dd <= d) {
            for (long long i = 1; i <= x; i++) {
                if (dp[i][dd] >= n) {
                    cout << i << '\n';
                    break;
                }
            }
        }
        else {
            if (n <= 2) {
                cout << 1 << '\n';
                continue;
            }
            __int128 D = dd;
            __int128 ans_2 = 6 * D - 2;
            if (ans_2 >= n) {
                cout << 2 << '\n';
                continue;
            }

            vector<vector<__int128>> v = {{2}, {4}, {8}};
            vector<vector<__int128>> mat = {{1, 0, 0}, {3, 1, 0}, {0, 7, 1}};
            mat = matexp(mat, dd - 1);
            v = matmul(mat, v);
            if (v[2][0] >= n) {
                cout << 3 << '\n';
                continue;
            }

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 52ms
memory: 293660kb

input:

1
4 1

output:

2

result:

ok single line: '2'

Test #2:

score: -100
Wrong Answer
time: 56ms
memory: 293676kb

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:

1
60
1
2
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
5
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6...

result:

wrong answer 1st lines differ - expected: '0', found: '1'