QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#433167#6637. Perfect Stringsucup-team3215WA 198ms159860kbC++231.2kb2024-06-08 06:23:252024-06-08 06:23:27

Judging History

你现在查看的是最新测评结果

  • [2024-06-08 06:23:27]
  • 评测
  • 测评结果:WA
  • 用时:198ms
  • 内存:159860kb
  • [2024-06-08 06:23:25]
  • 提交

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();
}

Details

Tip: Click on the bar to expand more detailed information

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'