QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#710066#5661. Multi-Laddersquannguyen2009AC ✓0ms3720kbC++23972b2024-11-04 18:23:452024-11-04 18:23:46

Judging History

This is the latest submission verdict.

  • [2024-11-04 18:23:46]
  • Judged
  • Verdict: AC
  • Time: 0ms
  • Memory: 3720kb
  • [2024-11-04 18:23:45]
  • Submitted

answer

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pb push_back
#define ii pair<int, int>
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
using namespace std;

const int N=1e5+5, mod = 1e9+7, inf = 1e18;

int n, k, v;

int binpow(int x, int y) {
    int res = 1;
    while(y) {
        if(y&1) res = (res*x)%mod;
        y>>=1;
        x = (x*x)%mod;
    }
    return res;
}

void solve() {
    cin >> n >> k >> v;
    if(v<=1) {
        cout << 0 << '\n';
        return;
    }
    int ring = binpow(v-1, k);
    ring = (ring+(v-1)*((k&1) ? mod-1 : 1))%mod;
    int sign = ((v-1)*(v-2)+1)%mod;
    sign = binpow(sign, (n-1)*k);
    cout << ring*sign%mod << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t; cin >> t;
    while(t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1
2 3 3

output:

162

result:

ok single line: '162'

Test #2:

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

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