QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#235289 | #6637. Perfect Strings | jzh# | WA | 362ms | 161420kb | C++20 | 1.6kb | 2023-11-02 16:57:12 | 2023-11-02 16:57:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 10000005;
const ll Ha = 1e9+7;
ll a[MAXN];
int jc[2*MAXN], ijc[2*MAXN];
ll ksm(ll x, ll k) {
ll ret = 1;
for (; k; k>>=1, x=x*x%Ha)
if (k&1) ret = ret*x %Ha;
return ret;
}
ll binom(ll x, ll y) {
return 1ll*ijc[y] * ijc[x-y] %Ha * jc[x] %Ha;
}
ll inv(ll x) {
if (x <= 1) return 1;
return 1ll*ijc[x] * jc[x-1] %Ha;
}
void solve()
{
ll n, c;
ll tmp, tmp1, tmp2, A, B, iA;
scanf("%lld%lld", &n, &c);
if (n == 1) {
printf("%lld\n", c);
return;
}
if (c == 1) {
puts("1");
return;
}
tmp1 = 1ll*2*(c-1) %Ha *(c-2) %Ha;
tmp2 = 1ll*2*c %Ha * (c-1) %Ha;
for (int i=1; i<=n; i++) {
tmp = 1ll*binom(2*i-1, i) * inv(2*i-1) %Ha * 2 %Ha * ksm(c-1, i);
a[i] = 1ll*tmp2 * tmp %Ha;
//a[i] = tmp;
}
a[0] = ((-tmp2 + tmp1)%Ha + Ha) %Ha;
A = (4-4*c%Ha + Ha) %Ha;
B = (1ll*4*c%Ha*c%Ha*(c-1)%Ha);
iA = ksm(A, Ha-2);
for (int i=0; i<=n; i++) {
a[i] = (a[i]%Ha + Ha) %Ha;
tmp = 1ll*a[i] * iA %Ha;
a[i+1] -= 1ll*B * tmp %Ha;
a[i] = tmp;
}
printf("%lld\n", a[n]);
}
int main()
{
int ttt;
scanf("%d", &ttt);
jc[0] = 1;
for (int i=1; i<2*MAXN; i++) jc[i] = 1ll*jc[i-1]*i %Ha;
ijc[2*MAXN-1] = ksm(jc[2*MAXN-1], Ha-2);
for (int i=2*MAXN-2; i>=0; i--) ijc[i] = 1ll*ijc[i+1] * (i+1) %Ha;
while (ttt--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 163ms
memory: 161420kb
input:
2 3 1 2 2
output:
1 6
result:
ok 2 number(s): "1 6"
Test #2:
score: 0
Accepted
time: 200ms
memory: 160464kb
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: 362ms
memory: 161040kb
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:
692428457 40620583 841364882 686501725 971203092 50038381 781301380 918724753 534299959 678839157 697667965 410584687 723182017 36152023 700087014 673726612 686021588 82686713 60132916 326566089 957499162 819786812 442152984 750270955 939107832 889268048 887586132 943154141 4832312 172517 513285783 ...
result:
wrong answer 1st numbers differ - expected: '89775996', found: '692428457'