結果
問題 | No.660 家を通り過ぎないランダムウォーク問題 |
ユーザー |
|
提出日時 | 2025-02-13 22:03:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 9 ms / 2,000 ms |
コード長 | 1,406 bytes |
コンパイル時間 | 1,489 ms |
コンパイル使用メモリ | 161,700 KB |
実行使用メモリ | 9,800 KB |
最終ジャッジ日時 | 2025-02-13 22:03:04 |
合計ジャッジ時間 | 3,078 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 45 |
ソースコード
//Date: 2025-02-13 20:59:03 #include<bits/stdc++.h> using namespace std; #define int long long #define P emplace_back #define CLEAR(a,v) memset(a,(v),sizeof(a)) #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define per(i,a,b) for(int i=(a);i>=(b);i--) //char buf[1<<20],*p1,*p2; //#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++) inline int rd() { int s=0,m=0;char ch=getchar(); while(!isdigit(ch)) {if(ch=='-')m=1;ch=getchar();} while( isdigit(ch)) s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return m?-s:s; } bool MBE; namespace SOLVER { const int N=400000,M=1e9+7;inline int qpow(int x,int y=M-2) {int s=1;for(;y;y>>=1,x=x*x%M) if(y&1) s=s*x%M;return s;} int fac[N+5],ifac[N+5];inline int C(int n,int m) {return n<m||m<0?0:fac[n]*ifac[m]%M*ifac[n-m]%M;} inline void add(int &x,int y) {x+=y;x>=M&&(x-=M);}inline void del(int &x,int y) {x-=y;x<0&&(x+=M);} void init() {fac[0]=1;rep(i,1,N) fac[i]=fac[i-1]*i%M;ifac[N]=qpow(fac[N]);per(i,N,1) ifac[i-1]=ifac[i]*i%M;} int f(int n,int m) {return (n+m)%2==1?0:C(n,(n+m)/2);} void MAIN() { init();int n=rd(),ans=0; rep(i,0,2*n-1) add(ans,f(i,n-1)),del(ans,f(i,n+1)); cout<<ans<<endl; } } bool MED; signed main() { //freopen(".in","r",stdin);freopen(".out","w",stdout); for(int tt=1;tt;tt--) SOLVER::MAIN(); cerr<<(&MBE-&MED)/1024<<" KB, "<<1000*clock()/CLOCKS_PER_SEC<<" ms\n"; return 0; }