結果
問題 | No.660 家を通り過ぎないランダムウォーク問題 |
ユーザー |
|
提出日時 | 2025-01-09 22:46:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 40 ms / 2,000 ms |
コード長 | 817 bytes |
コンパイル時間 | 2,615 ms |
コンパイル使用メモリ | 191,152 KB |
実行使用メモリ | 19,456 KB |
最終ジャッジ日時 | 2025-01-09 22:46:58 |
合計ジャッジ時間 | 5,701 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 45 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:34:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | scanf("%d", &n); | ~~~~~^~~~~~~~~~
ソースコード
#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; }