結果

問題 No.660 家を通り過ぎないランダムウォーク問題
ユーザー DAyamaCTFDAyamaCTF
提出日時 2018-03-16 17:19:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 1,163 bytes
コンパイル時間 1,386 ms
コンパイル使用メモリ 145,192 KB
実行使用メモリ 19,204 KB
最終ジャッジ日時 2023-08-23 11:50:56
合計ジャッジ時間 10,875 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
18,968 KB
testcase_01 AC 139 ms
19,028 KB
testcase_02 AC 138 ms
18,968 KB
testcase_03 AC 138 ms
19,108 KB
testcase_04 AC 138 ms
18,992 KB
testcase_05 AC 139 ms
19,036 KB
testcase_06 AC 139 ms
18,972 KB
testcase_07 AC 139 ms
19,200 KB
testcase_08 AC 139 ms
19,008 KB
testcase_09 AC 138 ms
19,180 KB
testcase_10 AC 139 ms
18,944 KB
testcase_11 AC 138 ms
19,028 KB
testcase_12 AC 139 ms
18,988 KB
testcase_13 AC 139 ms
18,984 KB
testcase_14 AC 138 ms
18,988 KB
testcase_15 AC 138 ms
18,960 KB
testcase_16 AC 139 ms
19,052 KB
testcase_17 AC 140 ms
19,040 KB
testcase_18 AC 139 ms
18,968 KB
testcase_19 AC 140 ms
18,992 KB
testcase_20 AC 139 ms
18,948 KB
testcase_21 AC 138 ms
19,008 KB
testcase_22 AC 139 ms
19,200 KB
testcase_23 AC 140 ms
18,992 KB
testcase_24 AC 139 ms
18,968 KB
testcase_25 AC 139 ms
18,944 KB
testcase_26 AC 138 ms
18,984 KB
testcase_27 AC 139 ms
18,984 KB
testcase_28 AC 139 ms
19,164 KB
testcase_29 AC 139 ms
18,956 KB
testcase_30 AC 138 ms
18,984 KB
testcase_31 AC 138 ms
18,952 KB
testcase_32 AC 139 ms
18,972 KB
testcase_33 AC 139 ms
19,164 KB
testcase_34 AC 138 ms
19,092 KB
testcase_35 AC 139 ms
18,976 KB
testcase_36 AC 138 ms
18,956 KB
testcase_37 AC 139 ms
19,092 KB
testcase_38 AC 139 ms
19,048 KB
testcase_39 AC 139 ms
19,100 KB
testcase_40 AC 139 ms
19,176 KB
testcase_41 AC 140 ms
18,992 KB
testcase_42 AC 139 ms
19,204 KB
testcase_43 AC 140 ms
18,968 KB
testcase_44 AC 139 ms
19,056 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:46:13: warning: iteration 1000000 invokes undefined behavior [-Waggressive-loop-optimizations]
     fac[i+1]=fac[i]*(i+1)%mod;
             ^
main.cpp:10:39: note: within this loop
 #define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
                                       ^
main.cpp:11:18: note: in expansion of macro ‘repl’
 #define rep(i,n) repl(i,0,n)
                  ^~~~
main.cpp:45:3: note: in expansion of macro ‘rep’
   rep(i,1000001){
   ^~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll mod_pow(ll x,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*x%mod;
    x=x*x%mod;
    n>>=1;
  }
  return res;
}

ll n;
ll fac[1000001],finv[1000001];

ll comb(ll a,ll r){
  if(a<0||r<0||a-r<0)return 0;
  return (fac[a]*finv[r]%mod)*finv[a-r]%mod;
}

int main(){
  fac[0]=1;
  rep(i,1000001){
    fac[i+1]=fac[i]*(i+1)%mod;
    finv[i]=mod_pow(fac[i],mod-2);
  }
  cin>>n;
  ll res=1;
  for(ll x=n+1,y=1;x+y<=2*n;x++,y++){
    ll xx=x-1,yy=y;
    ll rx=xx-n,ry=yy+n;
    (res+=comb(x+y-1,x-1)-comb(rx+ry,rx)+mod)%=mod;
  }
  cout<<res<<endl;
  return 0;
}
0