QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#524175#5661. Multi-Laddersucup-team3699#AC ✓0ms3580kbC++201.5kb2024-08-19 11:35:222024-08-19 11:35:24

Judging History

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

  • [2024-08-19 11:35:24]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3580kb
  • [2024-08-19 11:35:22]
  • 提交

answer

#include<iostream>
using namespace std;
#define int long long
const int mod = 1e9 + 7;
int mat[2][2];
int a[2];
int fpow(int x, int p){
    int ret = 1;
    while(p){
        if(p & 1)
            ret = ret * x % mod;
        x = x * x % mod;
        p >>= 1;
    }
    return ret;
}
void mul(){
    int ret[2][2] = {0, 0, 0, 0};
    for (int i = 0; i < 2; i++){
        for (int j = 0; j < 2; j++){
            for (int k = 0; k < 2; k++)
                ret[i][j] += mat[i][k] * mat[k][j] % mod, ret[i][j] %= mod;
        }
    }
    for (int i = 0; i < 2; i++)
        for (int j = 0; j < 2; j++)
            mat[i][j] = ret[i][j];
}
void mul2(){
    int ret[2] = {0, 0};
    ret[0] = mat[0][0] * a[0] + mat[0][1] * a[1], ret[0] %= mod;
    ret[1] = mat[1][0] * a[0] + mat[1][1] * a[1], ret[1] %= mod;
    a[0] = ret[0], a[1] = ret[1];
}
void solve(){
    int n, k, c;
    cin >> n >> k >> c;
    mat[0][0] = c - 2, mat[0][1] = c - 1, mat[1][0] = 1, mat[1][1] = 0;
    a[0] = c * (c - 1) % mod * (c - 2) % mod, a[1] = c * (c - 1) % mod;
    int tmp = k - 3;
    while(tmp){
        if(tmp & 1){
            mul2();
        }
        mul();
        tmp >>= 1;
    }
    int ans = a[0];
    int b = c - 1 + (c - 2) * (c - 2);
    b %= mod;
    ans = ans * fpow(b, k * (n - 1)) % mod;
    cout << ans << "\n";
}
signed main(){
    ios_base::sync_with_stdio(0), cin.tie(0);
    int t = 1;
    cin >> t;
    while(t--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3560kb

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

20
2 3 3
1 3 3
10 3 0
10 3 2
1 21 2
1 22 0
2000 15000 2000
12000 30000 200000
1000000000 3 3
2 1000000000 3
2 3 100000000
1000000000 1000000000 10
1000000000 3 100000000
2 1000000000 100000000
1 1000000000 10
1 1000000000 100000000
1 1000 100000000
1000000000 1000000000 0
1000000000 1000000000 1
100...

output:

162
6
0
0
0
0
349400141
243010659
52489881
53690844
176686901
218103365
558243892
991895211
693053429
883715672
80402569
0
0
311752813

result:

ok 20 lines