結果

問題 No.823 Many Shifts Easy
ユーザー tomatoma
提出日時 2019-04-26 22:40:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 905 bytes
コンパイル時間 1,539 ms
コンパイル使用メモリ 167,820 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-03 23:44:25
合計ジャッジ時間 2,080 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

ll P(ll l, ll r) {
	if (l < r)return 0;
	//if (l == r)return 1;
	ll res = 1;
	REP(i, r)res = (res*(l - i)) % MOD;
	return res;
}

int main()
{
	ll N, K;
	cin >> N >> K;
	ll left = ((N - 1)*N / 2) % MOD;
	ll way =
		(
			P(N - 1, K) +
			(
				N - 2 < K ? 0 :
				(
					P(N, K) - P(N - 1, K) * 2 + P(N - 2, K)
					) / 2
				)
			) % MOD;
	ll right = N == K
		? 0
		: P(N, K + 1) % MOD;
	ll res = (left*way%MOD + right) % MOD;
	cout << (res + MOD) % MOD << endl;
	return 0;
}
0