結果
問題 | No.660 家を通り過ぎないランダムウォーク問題 |
ユーザー |
|
提出日時 | 2018-03-02 23:38:36 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 739 bytes |
コンパイル時間 | 1,999 ms |
コンパイル使用メモリ | 159,772 KB |
実行使用メモリ | 16,728 KB |
最終ジャッジ日時 | 2024-06-22 13:13:10 |
合計ジャッジ時間 | 4,227 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 WA * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:50:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘ll’ {aka ‘long long int’} [-Wformat=] 50 | printf("%d\n",ans); | ~^ ~~~ | | | | int ll {aka long long int} | %lld main.cpp:35:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | scanf("%d",&n); | ~~~~~^~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair<int,int> P; ll fact[15000005]; ll extgcd(ll a,ll b,ll& x,ll& y){ ll d=a; if(b!=0LL){ d=extgcd(b,a%b,y,x); y-=(a/b)*x; }else{ x=1; y=0; } return d; } ll mod_inverse(ll a,ll m){ ll x,y; extgcd(a,m,x,y); return (m+x%m)%m; } int main(void){ fact[0]=1; for(ll i=1;i<=1400000;i++){ fact[i]=fact[i-1]*i%MOD; } int n; scanf("%d",&n); ll ans=0; for(int i=0;i*2<=n;i++){ if(i==0)ans++; if(i==1){ ans+=n; } if(i>=2){ ll val=fact[n+i*2-1]; val=val*mod_inverse(fact[n+i],MOD); val=(ll)val*n%MOD; val=val*mod_inverse(fact[i],MOD); ans=(ans+val)%MOD; } } printf("%d\n",ans); return 0; }