結果

問題 No.823 Many Shifts Easy
ユーザー tomatoma
提出日時 2019-04-26 22:10:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 757 bytes
コンパイル時間 1,326 ms
コンパイル使用メモリ 168,368 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-03 22:55:48
合計ジャッジ時間 1,822 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 WA -
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 1 ms
6,940 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) {
	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) + (P(N, K) - P(N - 1, K) * 2 + P(N - 2, K)) / 2) % MOD;
	ll right = P(N, K + 1);
	cout << (left*way + right + MOD * MOD) % MOD << endl;
	return 0;
}
0