結果

問題 No.823 Many Shifts Easy
ユーザー kotatsugamekotatsugame
提出日時 2019-10-12 20:20:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 534 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 66,196 KB
実行使用メモリ 5,004 KB
最終ジャッジ日時 2023-08-19 11:21:50
合計ジャッジ時間 1,446 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 13 ms
4,908 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 9 ms
4,380 KB
testcase_06 AC 15 ms
4,928 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 14 ms
5,004 KB
testcase_09 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long F[1<<17],I[1<<17];
int N,K;
long P(int a,int b){return a<b||b<0?0:F[a]*I[a-b]%mod;}
long C(int a,int b){return F[a]*I[b]%mod*I[a-b]%mod;}
main()
{
	cin>>N>>K;
	F[0]=1;
	for(int i=1;i<=N;i++)F[i]=F[i-1]*i%mod;
	I[N]=power(F[N],mod-2);
	for(int i=N;i--;)I[i]=I[i+1]*(i+1)%mod;
	long ans=0;
	for(int k=1;k<=N;k++)
	{
		(ans+=(P(N-1,K)+(k<N)*P(N-2,K-2)*C(K,2)%mod)%mod*k%mod)%=mod;
	}
	cout<<ans<<endl;
}
0