QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#79425 | #5532. Kangaroo | alpha1022 | 100 ✓ | 2ms | 3868kb | C++17 | 2.7kb | 2023-02-20 08:18:41 | 2023-02-20 08:18:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
int norm(int x) { return x >= mod ? x - mod : x; }
int reduce(int x) { return x < 0 ? x + mod : x; }
int neg(int x) { return x ? mod - x : 0; }
int quo2(int x) { return (x + (x & 1 ? mod : 0)) >> 1; }
void add(int &x, int y) { if ((x += y - mod) < 0) x += mod; }
void sub(int &x, int y) { if ((x -= y) < 0) x += mod; }
int mpow(int a, int b) {
int ret = 1;
for (; b; b >>= 1) {
if (b & 1) ret = (ll)ret * a % mod;
a = (ll)a * a % mod;
}
return ret;
}
const int N = 2e3 + 2;
int n, s, t;
int a, b, c;
bool vis[N + 5];
int prime[N + 5], cnt;
int aPool[N + 5], bPool[N + 5], cPool[N + 5];
int *aPow = aPool + 1, *bPow = bPool + 1, *cPow = cPool + 1;
int fac[N + 5], ifac[N + 5];
int binom(int n, int m) { return n < m || n < 0 ? 0 : (ll)fac[n] * ifac[m] % mod * ifac[n - m] % mod; }
int f[N + 5], delta0, delta1;
int ans;
int main() {
scanf("%d%d%d", &n, &s, &t);
if (s == t) { puts("0"); return 0; }
if (s < t) swap(s, t);
a = t - 1, b = s - t - 1, c = n - s, n -= 2;
aPow[-1] = a & 1 ? mod - 1 : 1, bPow[-1] = b & 1 ? mod - 1 : 1, cPow[-1] = c & 1 ? mod - 1 : 1,
aPow[0] = !a, bPow[0] = !b, cPow[0] = !c,
aPow[1] = bPow[1] = cPow[1] = 1;
for (int i = 2; i <= n + 1; ++i) {
if (!vis[i]) prime[++cnt] = i, aPow[i] = mpow(i, a), bPow[i] = mpow(i, b), cPow[i] = mpow(i, c);
for (int j = 1; j <= cnt && i * prime[j] <= n; ++j) {
vis[i * prime[j]] = 1,
aPow[i * prime[j]] = (ll)aPow[i] * aPow[prime[j]] % mod,
bPow[i * prime[j]] = (ll)bPow[i] * bPow[prime[j]] % mod,
cPow[i * prime[j]] = (ll)cPow[i] * cPow[prime[j]] % mod;
if (!(i % prime[j])) break;
}
}
fac[0] = 1;
for (int i = 1; i <= n + 2; ++i) fac[i] = (ll)fac[i - 1] * i % mod;
ifac[n + 2] = mpow(fac[n + 2], mod - 2);
for (int i = n + 2; i; --i) ifac[i - 1] = (ll)ifac[i] * i % mod;
for (int i = 0; i <= n + 2; ++i) {
if (i) sub(f[i], f[i - 1]);
if (i > 1) sub(f[i], quo2(f[i - 2]));
if (i <= 1) add(f[i], 1);
if (i == n + 1) delta0 = neg(f[i]), f[i] = 0;
if (i == n + 2) delta1 = neg(f[i]);
}
for (int i = 0; i <= n; ++i) {
f[i] = ((ll)(mod - delta0) * binom(n + 1, i) + (ll)delta1 * binom(n + 2, i)) % mod;
if ((n ^ i) & 1) f[i] = neg(f[i]);
if (i == 1) add(f[i], 1);
if (i > 1) sub(f[i], f[i - 2]);
if (n & 1) ans = (ans + ((ll)(mod - aPow[i + 1]) * cPow[i + 1] + (ll)aPow[i - 1] * cPow[i - 1]) % mod * bPow[i] % mod * f[i]) % mod;
else ans = (ans + ((ll)aPow[i + 1] * cPow[i - 1] + (ll)aPow[i - 1] * cPow[i + 1]) % mod * bPow[i] % mod * f[i]) % mod;
}
if (((n + 1) >> 1) & 1) ans = neg(ans);
printf("%d\n", ans);
}
詳細信息
Subtask #1:
score: 6
Accepted
Test #1:
score: 6
Accepted
time: 2ms
memory: 3604kb
input:
7 3 6
output:
14
result:
ok 1 number(s): "14"
Subtask #2:
score: 30
Accepted
Dependency #1:
100%
Accepted
Test #2:
score: 30
Accepted
time: 2ms
memory: 3856kb
input:
39 36 32
output:
964903316
result:
ok 1 number(s): "964903316"
Test #3:
score: 0
Accepted
time: 2ms
memory: 3848kb
input:
26 1 26
output:
955348527
result:
ok 1 number(s): "955348527"
Test #4:
score: 0
Accepted
time: 2ms
memory: 3828kb
input:
40 11 33
output:
695661890
result:
ok 1 number(s): "695661890"
Test #5:
score: 0
Accepted
time: 2ms
memory: 3660kb
input:
39 39 38
output:
717149364
result:
ok 1 number(s): "717149364"
Test #6:
score: 0
Accepted
time: 2ms
memory: 3572kb
input:
40 10 25
output:
912929610
result:
ok 1 number(s): "912929610"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
37 25 23
output:
250748685
result:
ok 1 number(s): "250748685"
Test #8:
score: 0
Accepted
time: 2ms
memory: 3560kb
input:
39 2 38
output:
624060592
result:
ok 1 number(s): "624060592"
Test #9:
score: 0
Accepted
time: 2ms
memory: 3616kb
input:
40 18 22
output:
739993796
result:
ok 1 number(s): "739993796"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
40 11 35
output:
135213497
result:
ok 1 number(s): "135213497"
Subtask #3:
score: 15
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #11:
score: 15
Accepted
time: 2ms
memory: 3836kb
input:
199 100 70
output:
914653136
result:
ok 1 number(s): "914653136"
Test #12:
score: 0
Accepted
time: 2ms
memory: 3860kb
input:
187 3 40
output:
928785584
result:
ok 1 number(s): "928785584"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
199 198 197
output:
38412688
result:
ok 1 number(s): "38412688"
Test #14:
score: 0
Accepted
time: 2ms
memory: 3840kb
input:
200 40 140
output:
367088143
result:
ok 1 number(s): "367088143"
Test #15:
score: 0
Accepted
time: 1ms
memory: 3684kb
input:
199 111 3
output:
870834793
result:
ok 1 number(s): "870834793"
Test #16:
score: 0
Accepted
time: 2ms
memory: 3688kb
input:
200 133 73
output:
343127012
result:
ok 1 number(s): "343127012"
Test #17:
score: 0
Accepted
time: 2ms
memory: 3716kb
input:
178 15 163
output:
160852284
result:
ok 1 number(s): "160852284"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
197 43 79
output:
332057544
result:
ok 1 number(s): "332057544"
Test #19:
score: 0
Accepted
time: 2ms
memory: 3652kb
input:
200 33 79
output:
742545318
result:
ok 1 number(s): "742545318"
Subtask #4:
score: 49
Accepted
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Test #20:
score: 49
Accepted
time: 2ms
memory: 3868kb
input:
658 169 438
output:
206087110
result:
ok 1 number(s): "206087110"
Test #21:
score: 0
Accepted
time: 2ms
memory: 3620kb
input:
700 207 509
output:
478311263
result:
ok 1 number(s): "478311263"
Test #22:
score: 0
Accepted
time: 2ms
memory: 3676kb
input:
755 139 507
output:
103783948
result:
ok 1 number(s): "103783948"
Test #23:
score: 0
Accepted
time: 2ms
memory: 3840kb
input:
2000 500 1500
output:
123410309
result:
ok 1 number(s): "123410309"
Test #24:
score: 0
Accepted
time: 2ms
memory: 3640kb
input:
2000 1000 1001
output:
956197482
result:
ok 1 number(s): "956197482"
Test #25:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
2000 666 1333
output:
993781645
result:
ok 1 number(s): "993781645"
Test #26:
score: 0
Accepted
time: 2ms
memory: 3628kb
input:
1991 198 677
output:
155058730
result:
ok 1 number(s): "155058730"
Test #27:
score: 0
Accepted
time: 2ms
memory: 3692kb
input:
1498 299 659
output:
665757882
result:
ok 1 number(s): "665757882"