QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#113684 | #5661. Multi-Ladders | UFRJ# | AC ✓ | 1ms | 3444kb | C++20 | 3.5kb | 2023-06-19 03:36:54 | 2023-06-19 03:36:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
const lint MOD = 1000000007;
template<unsigned M_> struct modnum {
static constexpr unsigned M = M_;
using ll = long long; using ull = unsigned long long; unsigned x;
// ec131c
constexpr modnum() : x(0U) {}
constexpr modnum(unsigned a) : x(a % M) {}
constexpr modnum(ull a) : x(a % M) {}
constexpr modnum(int a) : x(((a %= static_cast<int>(M)) < 0) ? (a + static_cast<int>(M)) : a) {}
constexpr modnum(ll a) : x(((a %= static_cast<ll>(M)) < 0) ? (a + static_cast<ll>(M)) : a) {}
// da738b
explicit operator int() const { return x; }
modnum& operator+=(const modnum& a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
modnum& operator-=(const modnum& a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
modnum& operator*=(const modnum& a) { x = unsigned((static_cast<ull>(x) * a.x) % M); return *this; }
modnum& operator/=(const modnum& a) { return (*this *= a.inv()); }
// ef603f
modnum operator+(const modnum& a) const { return (modnum(*this) += a); }
modnum operator-(const modnum& a) const { return (modnum(*this) -= a); }
modnum operator*(const modnum& a) const { return (modnum(*this) *= a); }
modnum operator/(const modnum& a) const { return (modnum(*this) /= a); }
modnum operator+() const { return *this; }
modnum operator-() const { modnum a; a.x = x ? (M - x) : 0U; return a; }
// b8b96c
template<typename T> friend modnum operator+(T a, const modnum& b) { return (modnum(a) += b); }
template<typename T> friend modnum operator-(T a, const modnum& b) { return (modnum(a) -= b); }
template<typename T> friend modnum operator*(T a, const modnum& b) { return (modnum(a) *= b); }
template<typename T> friend modnum operator/(T a, const modnum& b) { return (modnum(a) /= b); }
modnum pow(ll e) const {
if (e < 0) return inv().pow(-e);
modnum x2 = x, xe = 1U;
for (; e; e >>= 1) {
if (e & 1) xe *= x2;
x2 *= x2;
}
return xe;
}
modnum inv() const {
unsigned a = x, b = M; int y = 1, z = 0;
while (a) {
const unsigned q = (b/a), c = (b - q*a);
b = a, a = c; const int w = z - static_cast<int>(q) * y;
z = y, y = w;
} assert(b == 1U); return modnum(z);
}
friend modnum inv(const modnum& a) { return a.inv(); }
explicit operator bool() const { return x; }
friend bool operator==(const modnum& a, const modnum& b) { return a.x == b.x; }
friend bool operator!=(const modnum& a, const modnum& b) { return a.x != b.x; }
friend ostream &operator<<(ostream& os, const modnum& a) { return os << a.x; }
friend istream &operator>>(istream& in, modnum& n) { ull v_; in >> v_; n = modnum(v_); return in; }
};
using num = modnum<1000000007>;
void solve(){
lint n, k, l;
cin>>n>>k>>l;
if(l < 2){
cout<<"0\n";
return;
}
if(l == 2){
if(k % 2 == 0) cout<<"2\n";
else cout<<"0\n";
return;
}
num cycle = num(-1).pow(k) * num(l-1).pow(k) + l - 1;
cycle = num(-1).pow(k) * cycle;
num ladder = num((l-2) * (l-2) + l-1).pow(n-1);
ladder = ladder.pow(k);
num answer = ladder * cycle;
cout<<answer<<"\n";
}
int main(){
cin.tie(0)->sync_with_stdio(false);
int t; cin>>t;
while(t--){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3376kb
input:
1 2 3 3
output:
162
result:
ok single line: '162'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3444kb
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