QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#94855 | #5661. Multi-Ladders | SEM_PRESSAO_pedroteosousa# | AC ✓ | 2ms | 3340kb | C++23 | 1.7kb | 2023-04-08 00:20:48 | 2023-04-08 00:20:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(v) v.begin(),v.end()
#define pb push_back
void dbg_out() {cerr << endl; }
template< typename H, typename... T>
void dbg_out(H h, T... t) { cerr << ' ' << h; dbg_out(t...); }
#define dbg(...) { cerr << #__VA_ARGS__ << ':'; dbg_out(__VA_ARGS__); }
constexpr int MOD = 1e9+7;
struct mint {
int x;
mint(): x(0) {}
mint(int _x): x(_x%MOD<0?_x%MOD+MOD:_x%MOD) {}
void operator+=(mint rhs) { x += rhs.x; if(x>=MOD) x-=MOD; }
void operator-=(mint rhs) { x -= rhs.x; if(x<0) x+=MOD; }
void operator*=(mint rhs) { x *= rhs.x; x%=MOD; }
void operator/=(mint rhs) { *this *= rhs.inv(); }
mint operator+(mint rhs) { mint res=*this; res += rhs; return res; }
mint operator-(mint rhs) { mint res=*this; res -= rhs; return res; }
mint operator*(mint rhs) { mint res=*this; res *= rhs; return res; }
mint operator/(mint rhs) { mint res=*this; res /= rhs; return res; }
mint inv() { return this->pow(MOD-2); }
mint pow(int e) {
mint res(1);
for(mint p=*this; e>0; e/=2, p*=p) if(e%2)
res *= p;
return res;
}
};
using Z = mint;
void solve() {
int n, k, _l;
cin >> n >> k >> _l;
if(_l <= 2) {
cout << 0 << '\n';
return;
}
mint l(_l);
mint ans;
k--;
mint x = (l - 1);
mint y = x*x;
if(k%2 == 0) {
int h = k / 2;
ans += (y.pow(h + 1) - 1) / (y - 1);
ans -= x*(y.pow(h) - 1) / (y - 1);
ans -= 1;
} else {
int h = k / 2;
ans += x*(y.pow(h + 1) - 1) / (y - 1);
ans -= (y.pow(h + 1) - 1) / (y - 1);
ans += 1;
}
ans *= l;
mint ladder = ((l-1) * (l-1) - (l - 2)).pow(n-1).pow(k+1);
ans *= ladder;
cout << ans.x << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.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: 2ms
memory: 3340kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3296kb
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