QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#409018 | #6734. Click the Circle | GepiSAMA# | WA | 1ms | 4272kb | C++14 | 2.0kb | 2024-05-11 15:43:34 | 2024-05-11 15:43:34 |
Judging History
answer
#include <iostream>
#include <cstring>
using namespace std;
using i64 = long long;
const int mod = 1e9 + 7;
const int N = 210;
int fac[N], invfac[N];
int f[N], g[N];
int n, k;
i64 t;
int qpow(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
b >>= 1;
}
return res;
}
int inv(int x) {
return qpow(x, mod - 2);
}
void init_fac(int n) {
fac[0] = 1;
for (int i = 1; i <= n; i++) {
fac[i] = 1ll * fac[i - 1] * i % mod;
}
invfac[n] = inv(fac[n]);
for (int i = n - 1; ~i; i--) {
invfac[i] = 1ll * invfac[i + 1] * (i + 1) % mod;
}
}
int binom(int a, int b) {
if (a < b) return 0;
return 1ll * fac[a] * invfac[b] % mod * invfac[a - b] % mod;
}
struct Matrix {
int v[N][N];
Matrix (int t = 0) {
memset(v, 0, sizeof v);
for (int i = 0; i <= n; i++) {
v[i][i] = t;
}
}
Matrix operator* (Matrix& b) {
Matrix c;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
for (int k = 0; k <= n; k++)
c.v[i][j] = (c.v[i][j] + 1ll * v[i][k] * b.v[k][j] % mod) % mod;
return c;
}
Matrix operator^ (i64 b) {
Matrix res = 1, a = *this;
while (b) {
if (b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
};
int main() {
cin >> n >> t >> k;
Matrix B;
B.v[0][0] = B.v[n][n] = 1;
for (int i = 1; i < n; i++) {
B.v[i][i] = 1ll * (i * i + (n - i) * (n - i)) * inv(n * n) % mod;
B.v[i][i - 1] = B.v[i][i + 1] = 1ll * (n * i - i * i) * inv(n * n) % mod;
}
B = B ^ t;
for (int i = 0; i <= n; i++) {
g[i] = B.v[i][0];
}
init_fac(n);
for (int i = n; ~i; i--) {
f[i] = g[i];
for (int j = i + 1; j <= n; j++) {
f[i] -= 1ll * binom(n - i, j - i) * f[j] % mod;
f[i] = (f[i] + mod) % mod;
}
}
int res = 0;
for (int i = 0; i <= n - k; i++) {
res += 1ll * binom(n, i) * f[i] % mod;
res %= mod;
}
cout << res << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 4244kb
input:
2 1 1 1 1 1 2 1 2 2 3
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 4272kb
input:
2 1 1 1 1 1 2 1 3 2 3
output:
1
result:
wrong answer 1st numbers differ - expected: '0', found: '1'