結果
| 問題 | No.660 家を通り過ぎないランダムウォーク問題 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-01-09 22:46:51 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 2,000 ms |
| コード長 | 817 bytes |
| 記録 | |
| コンパイル時間 | 1,364 ms |
| コンパイル使用メモリ | 211,040 KB |
| 実行使用メモリ | 19,584 KB |
| 最終ジャッジ日時 | 2026-06-09 16:27:00 |
| 合計ジャッジ時間 | 4,301 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 45 |
ソースコード
#include <bits/stdc++.h>
using LL = long long;
const int N = 2e6 + 7;
const int MOD = 1e9 + 7;
int fac[N], ifc[N], n, m, k;
int pow(int x, int y) {
int ret = 1;
while(y) {
if(y & 1)
ret = 1LL * ret * x % MOD;
x = 1LL * x * x % MOD;
y >>= 1;
}
return ret;
}
int com(int x, int y) {
return x >= y && y >= 0 ? 1LL * fac[x] * ifc[y] % MOD * ifc[x - y] % MOD : 0;
}
int main() {
fac[0] = 1;
for(int i = 1; i < N; ++i)
fac[i] = 1LL * fac[i - 1] * i % MOD;
ifc[N - 1] = pow(fac[N - 1], MOD - 2);
for(int i = N - 2; i >= 0; --i)
ifc[i] = 1LL * ifc[i + 1] * (i + 1) % MOD;
scanf("%d", &n);
int ans = 0;
for(int i = 0; i <= n / 2; ++i)
ans = (ans + com(n + 2 * i - 1, i) - com(n + 2 * i - 1, n + i)) % MOD;
printf("%d\n", (ans + MOD) % MOD);
return 0;
}