結果
問題 | No.823 Many Shifts Easy |
ユーザー | hipopo |
提出日時 | 2020-04-22 15:18:18 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 3,267 bytes |
コンパイル時間 | 1,445 ms |
コンパイル使用メモリ | 138,508 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 07:11:25 |
合計ジャッジ時間 | 2,111 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 4 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 3 ms
5,248 KB |
testcase_06 | AC | 7 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 3 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
ソースコード
#include <algorithm> #include <cmath> #include <complex> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #include <functional> #include <cstring> #include <regex> #include <random> #include <cassert> #include <stack> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, s, n) for (int i = (s); i < (int)(n); i++) #define revrep(i, n) for (int i = (n) - 1; i >= 0; i--) #define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--) #define debug(x) cerr << #x << ": " << x << "\n" #define popcnt(x) __builtin_popcount(x) const double PI = acos(-1.0); using ll = long long; using P = pair<int, int>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T> istream& operator >>(istream &is, vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i); return is; } template<class T, class U> ostream& operator <<(ostream &os, pair<T, U> p) { cout << '(' << p.first << ", " << p.second << ')'; return os; } template<class T> void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; } template<class T> void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); } struct ModInt { static ll mod; ll val; ModInt(ll v = 0) : val(v % mod) {} ModInt operator-() const { return ModInt(val ? mod - val : val); } ModInt &operator+=(ModInt a) { if ((val += a.val) >= mod) val -= mod; return *this; } ModInt &operator-=(ModInt a) { if ((val -= a.val) < 0) val += mod; return *this; } ModInt &operator*=(ModInt a) { val = (__uint128_t(val) * a.val) % mod; return *this; } ModInt &operator/=(ModInt a) { ll u = 1, v = a.val, s = 0, t = mod; while (v) { ll q = t / v; swap(s -= u * q, u); swap(t -= v * q, v); } a.val = (s < 0 ? s + mod : s); val /= t; return (*this) *= a; } ModInt inv() const { return ModInt(1) /= (*this); } bool operator<(ModInt x) const { return val < x.val; } }; ll ModInt::mod = 1e9 + 7; ostream &operator<<(ostream &os, ModInt a) { os << a.val; return os; } ModInt operator+(ModInt a, ModInt b) { return a += b; } ModInt operator-(ModInt a, ModInt b) { return a -= b; } ModInt operator*(ModInt a, ModInt b) { return a *= b; } ModInt operator/(ModInt a, ModInt b) { return a /= b; } ModInt pow(ModInt a, ll e) { ModInt x(1); for (; e > 0; e /= 2) { if (e % 2 == 1) x *= a; a *= a; } return x; } ModInt comb(int n, int k) { ModInt x = 1, y = 1; rep(i, k) { x *= n - i; y *= i + 1; } return x / y; } ModInt perm(ll n, ll k) { if (n < k) return 0; ModInt res = 1; rep(i, k) res *= n - i; return res; } int main() { ll n, k; cin >> n >> k; ModInt ans = (perm(n - 1, k) + (k * (k - 1) / 2 * perm(n - 2, k - 2))) * (n - 1) * n / 2; ans += perm(n - 1, k) * n; cout << ans << endl; }