結果
| 問題 |
No.823 Many Shifts Easy
|
| コンテスト | |
| ユーザー |
cotton_fn_
|
| 提出日時 | 2019-04-26 22:23:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 76 ms / 2,000 ms |
| コード長 | 1,723 bytes |
| コンパイル時間 | 976 ms |
| コンパイル使用メモリ | 112,812 KB |
| 最終ジャッジ日時 | 2025-01-07 03:13:58 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>
using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x)
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0)
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs
const i64 mod = 1e9 + 7;
i64 fact_memo[200001];
i64 fact(i64 x) {
if (x == 0) return 1;
if (fact_memo[x]) return fact_memo[x];
return fact_memo[x] = x * fact(x - 1) % mod;
}
i64 ipow(i64 a, i64 b) {
return (b & 1 ? a : 1) * (b > 1 ? ipow(a * a % mod, b >> 1) : 1) % mod;
}
i64 fact_inv(i64 x) {
return ipow(fact(x), mod - 2);
}
i64 perm(i64 a, i64 b) {
return fact(a) * fact_inv(a - b) % mod;
}
i64 conb(i64 a, i64 b) {
return fact(a) * fact_inv(b) % mod * fact_inv(a - b) % mod;
}
int main() {
i64 n, k;
cin >> n >> k;
i64 ans = 0;
for (i64 x = 1; x <= n; ++x) {
ans = (ans
+ x * (
perm(n, k)
- k * perm(n - 1, k - 1) % mod
+ ((x < n || k ==1) ? k * (k - 1) / 2 % mod * perm(n - 2, k - 2) % mod : 0)
+ 2 * mod) % mod
) % mod;
}
cout << ans << '\n';
return 0;
}
cotton_fn_