QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#225327 | #5661. Multi-Ladders | BUET_Twilight# | AC ✓ | 1ms | 3892kb | C++23 | 2.3kb | 2023-10-24 14:58:20 | 2023-10-24 14:58:20 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0)
#define setbit0(n, i) ((n) & (~(1LL << (i))))
#define setbit1(n, i) ((n) | (1LL << (i)))
#define togglebit(n, i) ((n) ^ (1LL << (i)))
#define lastone(n) ((n) & (-(n)))
char gap = 32;
#define int long long
#define ll long long
#define lll __int128_t
#define pb push_back
// #define double long double
#define pii pair<int,int>
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;
typedef pair<double, double> pdd;
const double EPS = 1e-12;
typedef vector<vector<int>> matrix;
const int mod = 1e9 + 7;
matrix mul(matrix a, matrix b){
int n = a.size();
matrix c(n, vector<int>(n));
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
for(int k=0;k<n;k++){
c[i][j] += a[i][k]*b[k][j] % mod;
c[i][j] %= mod;
}
}
}
return c;
}
long long binpow(long long a, long long b, long long m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
matrix power(matrix a, int b){
int n = a.size();
matrix res(n, vector<int>(n));
for(int i=0;i<n;i++) res[i][i] = 1;
while(b){
if(b&1) res = mul(res, a);
a = mul(a, a);
b >>= 1;
}
return res;
}
void solve(){
int n, k, l;
cin >> n >> k >> l;
matrix b = {
{0, 1},
{l-1, l-2},
};
matrix a = {
{l},
{0},
};
matrix res = mul(power(b, k-1), a);
int val = res[1][0];
int e = (l * l - 3*l + 3) % mod;
e = binpow(e, n-1, mod);
e = binpow(e, k, mod);
cout << (e * val) % mod << "\n";
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tc;
cin>>tc;
while(tc--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3644kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3892kb
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