QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#656956 | #5661. Multi-Ladders | ucup-team5234# | AC ✓ | 1ms | 3600kb | C++23 | 1.2kb | 2024-10-19 13:56:12 | 2024-10-19 13:56:14 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
ll MOD = 1000000007;
using vll = vector<vector<ll>>;
#define rep(i,n) for(int i=0;i<n;i++)
vll mul(vll a, vll b) {
ll x = a.size();
ll y = b.size();
ll z = b[0].size();
vll ret(x, vector(z, 0LL));
for(int i = 0; i < x; i ++) {
for(int j = 0; j < z; j ++) {
for(int k = 0; k < y; k ++) {
ret[i][j] += a[i][k] * b[k][j] % MOD;
if(ret[i][j] >= MOD) ret[i][j] -= MOD;
}
}
}
return ret;
}
vll pow(vll a, ll n) {
vll ret(a.size(), vector(a.size(), 0LL));
rep(i, a.size())ret[i][i] = 1;
while(n) {
if(n & 1) {
ret = mul(ret, a);
}
a = mul(a, a);
n /= 2;
}
return ret;
}
int main(){
ll t;
cin >> t;
rep(_, t){
ll n,k,l;
cin >> n >> k >> l;
ll A = (l-1) + (l-2)*(l-2);
A %= MOD;
vll a(1, vector<ll>(1, A));
auto b = pow(a, (n-1)*k);
vll c = {{0,1},{l-1, l-2}};
auto d = pow(c, k);
vll e = {{l}, {0}};
auto f = mul(d, e);
ll ans = b[0][0] * f[0][0];
cout << ans%MOD << endl;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3600kb
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