結果
| 問題 |
No.660 家を通り過ぎないランダムウォーク問題
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2025-07-26 21:33:55 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 2,000 ms |
| コード長 | 725 bytes |
| コンパイル時間 | 1,412 ms |
| コンパイル使用メモリ | 162,192 KB |
| 実行使用メモリ | 9,932 KB |
| 最終ジャッジ日時 | 2025-07-26 21:33:59 |
| 合計ジャッジ時間 | 2,569 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 45 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
24 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=4e5+5;
const int mod=1e9+7;
int n;
ll jc[N],ny[N];
ll ksm(ll x,int y=mod-2){
ll an=1;
while(y){
if(y&1)an=an*x%mod;
x=x*x%mod;
y>>=1;
}
return an;
}
ll C(int x,int y){
if(x<y)return 0;
if(y<0)return 0;
return jc[x]*ny[y]%mod*ny[x-y]%mod;
}
ll ans;
int main(){
scanf("%d",&n);
jc[0]=1;
for(int i=1;i<=(n<<1);++i){
jc[i]=jc[i-1]*i%mod;
}
ny[n<<1]=ksm(jc[n<<1]);
for(int i=(n<<1);i;--i)ny[i-1]=ny[i]*i%mod;
for(int i=n-1;i<=(2*n-1);i+=2){
int cn=n-1+(i-(n-1))/2;
ans=(ans+C(i,cn)+mod-C(i,cn+1))%mod;
}
printf("%lld\n",ans);
return 0;
}
vjudge1