結果
問題 |
No.660 家を通り過ぎないランダムウォーク問題
|
ユーザー |
![]() |
提出日時 | 2025-07-25 23:05:33 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 989 bytes |
コンパイル時間 | 1,494 ms |
コンパイル使用メモリ | 162,320 KB |
実行使用メモリ | 17,132 KB |
最終ジャッジ日時 | 2025-07-25 23:05:47 |
合計ジャッジ時間 | 12,175 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 38 TLE * 1 -- * 6 |
ソースコード
#include<bits/stdc++.h> #define int long long using namespace std; const int N=200010; const int INF=0x3f3f3f3f3f3f3f3f; const int mod=1e9+7; int inv[N]; int ijc[N]; int jc[N]; void init(int n){ inv[1]=1; jc[0]=1; ijc[0]=1; for(int i=2;i<=n;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod; for(int i=1;i<=n;i++){ jc[i]=jc[i-1]*i%mod; ijc[i]=ijc[i-1]*inv[i]%mod; } return; } int C(int n,int m){ if(n<m)return 0; int fz=jc[n]; int fm=ijc[m]*ijc[n-m]%mod; return fz*fm%mod; } int n; int ans; int dp[N]; signed main(){ // ios::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); // freopen("walk.in","r",stdin); // freopen("walk.out","w",stdout); init(N-10); cin>>n; for(int i=n;i<=2*n;i+=2){ dp[i]=C(i,n+(i-n)/2); for(int j=n;j<=i-2;j++){ dp[i]-=dp[j]*C(i-j,(i-j)/2)%mod; dp[i]%=mod; } dp[i]=(dp[i]%mod+mod)%mod; // cerr<<dp[i]<<"\n"; ans=(ans+dp[i])%mod; } cout<<ans<<"\n"; return 0; } /* dp[i]=C(i,n)-dp[n]*C(i-n,(i-n)/2)-dp[n+2]*C(i-(n+2),i-(n+2)/2)-... */