QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#290346#6558. Allergen TestingakshaykhandelwalWA 51ms293852kbC++202.6kb2023-12-24 21:07:292023-12-24 21:07:30

Judging History

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

  • [2023-12-24 21:07:30]
  • 评测
  • 测评结果:WA
  • 用时:51ms
  • 内存:293852kb
  • [2023-12-24 21:07:29]
  • 提交

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));
    for (int i = 0; i <= d; i++) dp[0][i] = 1;

    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 (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}, {0, 3, 1, 0}, {0, 0, 7, 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: 51ms
memory: 293852kb

input:

1
4 1

output:

2

result:

ok single line: '2'

Test #2:

score: -100
Wrong Answer
time: 51ms
memory: 293728kb

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

result:

wrong answer 8th lines differ - expected: '3', found: '2'