QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#433162#6637. Perfect Stringsucup-team3215WA 304ms160068kbC++231.3kb2024-06-08 06:18:142024-06-08 06:18:15

Judging History

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

  • [2024-06-08 06:18:15]
  • 评测
  • 测评结果:WA
  • 用时:304ms
  • 内存:160068kb
  • [2024-06-08 06:18:14]
  • 提交

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];
}

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;
    vector<int> small(n + 1, 1), big(n + 1, 1);
    for (ll i = 1; i <= n; ++i)small[i] = (ll) (c - 1) * small[i - 1] % mod;
    for (ll i = 1; i <= n; ++i)big[i] = (ll) c * big[i - 1] % mod;
    ll res = 0;
    for (ll t = 1; t <= n; ++t) {
        ll ways = T(n - 1, n - t);
        (res += ways * big[t] % mod * small[n - t]) %= 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: 100
Accepted
time: 135ms
memory: 160068kb

input:

2
3 1
2 2

output:

1
6

result:

ok 2 number(s): "1 6"

Test #2:

score: 0
Accepted
time: 199ms
memory: 159864kb

input:

100000
1 1
4 1
5 5
3 5
1 2
5 3
1 1
3 3
5 2
2 1
4 1
5 5
2 3
4 1
3 3
2 5
3 2
4 3
4 4
3 5
3 1
5 2
2 2
4 2
5 4
1 2
3 1
4 5
2 5
5 3
1 5
5 2
3 2
5 2
4 1
1 3
3 2
4 5
2 1
4 1
2 2
1 1
3 5
4 5
2 3
3 5
2 5
2 4
5 4
2 3
1 1
2 1
4 4
1 5
5 4
1 3
5 4
4 5
1 3
1 1
3 3
2 4
2 4
2 1
5 5
1 3
2 3
4 1
4 3
2 4
2 4
4 2
1 1
1...

output:

1
1
71445
485
2
3543
1
87
252
1
1
71445
15
1
87
45
20
543
2092
485
1
252
6
70
19864
2
1
5725
45
3543
5
252
20
252
1
3
20
5725
1
1
6
1
485
5725
15
485
45
28
19864
15
1
1
2092
5
19864
3
19864
5725
3
1
87
28
28
1
71445
3
15
1
543
28
28
70
1
1
71445
15
2092
3
1
2
15
87
2092
19864
71445
6
252
2092
252
15...

result:

ok 100000 numbers

Test #3:

score: -100
Wrong Answer
time: 304ms
memory: 159868kb

input:

100000
94 7867320
84 1294950
35 8570570
72 7050952
23 3907221
95 7482398
58 2363048
44 2234552
50 8809524
37 1061961
19 884367
38 3261675
59 1563189
61 7603994
83 3131714
19 6207284
64 5662457
2 6845951
84 4688192
13 7552675
38 3119650
84 6311084
10 5040332
53 5981961
46 7308176
43 679952
30 2922213...

output:

-463113614
-390912345
656361379
-787573326
292967555
145571335
734040539
-343859177
659429850
-289204710
309476303
-239877634
160856168
-200944143
993085880
87939540
4577429
82686713
318903393
-576581972
72830018
-519157130
6430981
-167179533
-286590256
965045151
554244516
23969233
354639060
8617740...

result:

wrong answer 1st numbers differ - expected: '89775996', found: '-463113614'