結果
| 問題 |
No.660 家を通り過ぎないランダムウォーク問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-03-02 23:37:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 737 bytes |
| コンパイル時間 | 1,952 ms |
| コンパイル使用メモリ | 159,104 KB |
| 実行使用メモリ | 8,904 KB |
| 最終ジャッジ日時 | 2024-06-22 13:02:55 |
| 合計ジャッジ時間 | 3,264 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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[5000005];
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<=400000;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;
}