結果

問題 No.834 Random Walk Trip
ユーザー kotatsugamekotatsugame
提出日時 2019-05-25 00:54:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 779 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 73,888 KB
実行使用メモリ 24,644 KB
最終ジャッジ日時 2023-10-17 17:36:29
合計ジャッジ時間 2,825 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
20,020 KB
testcase_01 AC 40 ms
20,020 KB
testcase_02 AC 40 ms
20,020 KB
testcase_03 AC 41 ms
20,020 KB
testcase_04 AC 41 ms
20,076 KB
testcase_05 AC 40 ms
20,076 KB
testcase_06 AC 41 ms
20,076 KB
testcase_07 AC 40 ms
20,076 KB
testcase_08 AC 41 ms
20,076 KB
testcase_09 AC 40 ms
20,076 KB
testcase_10 AC 40 ms
20,076 KB
testcase_11 AC 41 ms
20,076 KB
testcase_12 AC 40 ms
20,076 KB
testcase_13 AC 40 ms
20,076 KB
testcase_14 AC 41 ms
20,076 KB
testcase_15 AC 40 ms
20,076 KB
testcase_16 AC 41 ms
20,076 KB
testcase_17 AC 40 ms
20,076 KB
testcase_18 AC 40 ms
20,076 KB
testcase_19 AC 41 ms
20,076 KB
testcase_20 AC 40 ms
20,076 KB
testcase_21 AC 40 ms
20,080 KB
testcase_22 AC 41 ms
20,076 KB
testcase_23 AC 64 ms
24,644 KB
testcase_24 AC 40 ms
20,076 KB
testcase_25 AC 70 ms
24,644 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long mod=1e9+7,F[1<<20],I[1<<20];
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long C(int a,int b){return F[a]*I[b]%mod*I[a-b]%mod;}
int N,M;
main()
{
	F[0]=1;
	for(int i=1;i<1<<20;i++)F[i]=F[i-1]*i%mod;
	I[(1<<20)-1]=power(F[(1<<20)-1],mod-2);
	for(int i=(1<<20)-1;i--;)I[i]=I[i+1]*(i+1)%mod;
	cin>>N>>M;
	if(N==1)
	{
		cout<<1<<endl;
		return 0;
	}
	vector<int>a;
	for(int i=0;i<=M+1;i+=2*N)
	{
		if(i<=M)a.push_back(i);
		if(i&&i<=M)a.push_back(-i);
		if(abs(i-1)<=M)a.push_back(i-1);
		if(i&&abs(-i-1)<=M)a.push_back(-i-1);
	}
	long ans=0;
	for(int j:a)
	{
		j=abs(j);
		if((M-j)%2==1)continue;
		int X=j+(M-j)/2,Y=(M-j)/2;
		ans=(ans+C(M,X))%mod;
	}
	cout<<ans<<endl;
}
0