QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#433167 | #6637. Perfect Strings | ucup-team3215 | WA | 198ms | 159860kb | C++23 | 1.2kb | 2024-06-08 06:23:25 | 2024-06-08 06:23:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll N = 2e7 + 5;
int fact[N + 1], inv[N + 1];
ll C(ll n, ll k) {
if (k < 0)return 0;
return (ll) fact[n] * inv[k] % mod * inv[n - k] % mod;
}
ll obr(ll n) {
return (ll) inv[n] * fact[n - 1] % mod;
}
ll T(ll n, ll k) {
return C(n + k, n) * (n - k + 1) % mod * obr(n + 1) % mod;
}
ll modPow(ll x, ll n) {
if (!n)return 1;
ll u = modPow(x, n / 2);
u = u * u % mod;
if (n % 2)u = u * x % mod;
return u;
}
void solve() {
ll n, c;
cin >> n >> c;
ll res = 0;
ll big = c;
ll small = modPow(c - 1, n - 1);
for (ll t = 1; t <= n; ++t) {
ll ways = T(n - 1, n - t);
(res += ways * big % mod * small) %= mod;
big = big * c % mod;
small = small * obr(c - 1) % mod;
}
cout << res << "\n";
}
int main() {
cin.tie(0)->sync_with_stdio(false);
fact[0] = 1;
for (ll i = 1; i <= N; ++i)fact[i] = (ll) fact[i - 1] * i % mod;
inv[N] = modPow((ll) fact[N], mod - 2);
for (ll i = N - 1; ~i; --i) {
inv[i] = (ll) inv[i + 1] * (i + 1) % mod;
}
ll t;
cin >> t;
while (t--)solve();
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 198ms
memory: 159860kb
input:
2 3 1 2 2
output:
0 6
result:
wrong answer 1st numbers differ - expected: '1', found: '0'