QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#433161#6637. Perfect Stringsucup-team3215WA 290ms160024kbC++231.3kb2024-06-08 06:17:472024-06-08 06:17:47

Judging History

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

  • [2024-06-08 06:17:47]
  • 评测
  • 测评结果:WA
  • 用时:290ms
  • 内存:160024kb
  • [2024-06-08 06:17:47]
  • 提交

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

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 203ms
memory: 159800kb

input:

2
3 1
2 2

output:

1
6

result:

ok 2 number(s): "1 6"

Test #2:

score: 0
Accepted
time: 217ms
memory: 159824kb

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: 290ms
memory: 160024kb

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:

700665292
727723366
10344475
588213569
417901331
193859072
-609340093
-8446177
-36668166
373009042
-786281046
-452471244
-43079159
864450195
-143345589
-880736858
315442172
82686713
-321571786
-399934551
-330779983
464242707
537780759
-142378663
-390586280
44384335
616079194
-24706486
620253787
5884...

result:

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