結果
問題 | No.1785 Inequality Signs |
ユーザー | 8UqsVg4r |
提出日時 | 2021-12-12 22:14:03 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 79 ms / 2,000 ms |
コード長 | 8,107 bytes |
コンパイル時間 | 3,900 ms |
コンパイル使用メモリ | 243,308 KB |
実行使用メモリ | 15,348 KB |
最終ジャッジ日時 | 2024-07-22 23:27:57 |
合計ジャッジ時間 | 7,499 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
15,232 KB |
testcase_01 | AC | 26 ms
15,104 KB |
testcase_02 | AC | 59 ms
15,232 KB |
testcase_03 | AC | 76 ms
15,104 KB |
testcase_04 | AC | 17 ms
15,104 KB |
testcase_05 | AC | 41 ms
15,104 KB |
testcase_06 | AC | 68 ms
15,104 KB |
testcase_07 | AC | 17 ms
15,104 KB |
testcase_08 | AC | 65 ms
15,104 KB |
testcase_09 | AC | 24 ms
15,104 KB |
testcase_10 | AC | 51 ms
15,104 KB |
testcase_11 | AC | 27 ms
15,172 KB |
testcase_12 | AC | 37 ms
15,232 KB |
testcase_13 | AC | 23 ms
15,168 KB |
testcase_14 | AC | 44 ms
15,104 KB |
testcase_15 | AC | 36 ms
15,104 KB |
testcase_16 | AC | 32 ms
15,104 KB |
testcase_17 | AC | 52 ms
15,224 KB |
testcase_18 | AC | 54 ms
15,036 KB |
testcase_19 | AC | 45 ms
15,168 KB |
testcase_20 | AC | 50 ms
15,232 KB |
testcase_21 | AC | 46 ms
15,104 KB |
testcase_22 | AC | 26 ms
15,104 KB |
testcase_23 | AC | 33 ms
15,140 KB |
testcase_24 | AC | 74 ms
15,104 KB |
testcase_25 | AC | 40 ms
15,104 KB |
testcase_26 | AC | 37 ms
15,104 KB |
testcase_27 | AC | 74 ms
15,104 KB |
testcase_28 | AC | 75 ms
15,348 KB |
testcase_29 | AC | 74 ms
15,148 KB |
testcase_30 | AC | 74 ms
15,104 KB |
testcase_31 | AC | 79 ms
15,192 KB |
testcase_32 | AC | 78 ms
15,140 KB |
testcase_33 | AC | 16 ms
15,104 KB |
testcase_34 | AC | 18 ms
15,200 KB |
testcase_35 | AC | 20 ms
15,056 KB |
testcase_36 | AC | 56 ms
15,104 KB |
testcase_37 | AC | 46 ms
15,200 KB |
testcase_38 | AC | 42 ms
15,232 KB |
testcase_39 | AC | 27 ms
15,232 KB |
testcase_40 | AC | 31 ms
15,152 KB |
testcase_41 | AC | 39 ms
15,040 KB |
testcase_42 | AC | 63 ms
15,020 KB |
testcase_43 | AC | 73 ms
15,104 KB |
testcase_44 | AC | 61 ms
15,232 KB |
testcase_45 | AC | 28 ms
15,172 KB |
testcase_46 | AC | 41 ms
15,104 KB |
testcase_47 | AC | 33 ms
15,104 KB |
testcase_48 | AC | 41 ms
15,104 KB |
testcase_49 | AC | 17 ms
15,232 KB |
testcase_50 | AC | 61 ms
15,232 KB |
testcase_51 | AC | 22 ms
15,200 KB |
testcase_52 | AC | 19 ms
15,104 KB |
testcase_53 | AC | 23 ms
15,264 KB |
ソースコード
//////___/_/////////////////////////////////_////____//__//// // / ___(_)_ _____ _ __ ___ ___ / \ / ___| | | // // | | _| \ \ / / _ \ | '_ ` _ \ / _ \ / _ \| | | | // // | |_| | |\ V / __/ | | | | | | __/ / ___ \ |___ |_| // // \____|_| \_/ \___| |_| |_| |_|\___| /_/ \_\____| (_) // /////////////////////////////////////////////////////////// #include <bits/stdc++.h> #include <type_traits> using namespace std; #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif using ll = long long; using ld = long double; #define Sugsugar cin.tie(0);ios::sync_with_stdio(false) extern const ll MOD; const ll INF = (ll)2e16; const int Inf = 2e9; const int MAX = 500000; const ld PI = (acos(-1)); template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;} template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;} ld rad(ld a) {return a * PI / 180.0;} const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};//2次元グリッド上のx軸方向 const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};//2次元グリッド上のy軸方向 template<class T> void rm(vector<T> &vec) {vec.erase(unique(vec.begin(), vec.end()), vec.end());} void rm(string &vec) {vec.erase(unique(vec.begin(), vec.end()), vec.end());} struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) { } int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool same(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; template <typename T> struct BIT { int n; // 配列の要素数(数列の要素数+1) vector<T> bit; // データの格納先 BIT(int n_) : n(n_ + 1), bit(n, 0) {} void add(int i, T x) { for (int idx = i; idx < n; idx += (idx & -idx)) { bit[idx] += x; } } T sum(int i) { T s(0); for (int idx = i; idx > 0; idx -= (idx & -idx)) { s += bit[idx]; } return s; } }; vector<pair<ll, ll>> factorize(ll N) { vector<pair<ll, ll>> res; for (ll a = 2; a * a <= N; ++a) { if (N % a != 0) continue; ll ex = 0; // 指数 // 割れる限り割り続ける while (N % a == 0) { ++ex; N /= a; } // その結果を push res.push_back({a, ex}); } // 最後に残った数について if (N != 1) res.push_back({N, 1}); return res; } ll mod(ll val,ll md = MOD) { ll res = val % md; if (res < 0) res += md; return res; } char upper(char c){ if('a' <= c && c <= 'z'){ c = c - ('a' - 'A'); } return c; } char lower(char c){ if('A' <= c && c <= 'Z'){ c = c + ('a' - 'A'); } return c; } ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 ll COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll Expo(ll N,ll K,ll md = MOD) { if (md == 0) { ll sum = 1; for (int i = 0; i < K; i++) sum *= N; return sum; } if (md == 1) return 0; N %= md; if (K == 0) { return 1; } ll Kc = K,rui = N,ans = 1; while(Kc) { if (Kc % 2) { ans *= rui; ans %= md; } rui *= rui; rui %= md; Kc /= 2; } return ans; } ll extGCD(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1; y = 0; return a; } ll d = extGCD(b, a%b, y, x); // 再帰的に解く y -= a / b * x; return d; } template<class T> constexpr auto unit() -> enable_if_t<is_integral<T>::value, T> { return 1; } template<class T> constexpr auto unit() -> enable_if_t<is_floating_point<T>::value, T> { return 1e-14; } template<class T> T sqroot(T Ex) { T l = 0,r = min(Ex,(T)(1e9)); while (r - l > unit<T>()) { T val = (l + r) / 2; if (val * val > Ex) r = val; else l = val; } return l;//Ex以下のT型の平方根 } template<class T> void sitpress(vector<T> &vec) { vector<T> array = vec; sort(array.begin(),array.end()); rm(array); for (int i = 0; i < vec.size(); i++) { int l = -1,r = array.size(); while (r - l > 1) { int mid = (l + r) / 2; if (array.at(mid) >= vec.at(i)) r = mid; else l = mid; } vec.at(i) = r; } } template<class T> ll Rolling(vector<T> Girl) { BIT<int> RG(Girl.size()); int si = Girl.size(); ll gl = 0; sitpress(Girl); for (int i = 0; i < si; i++) { Girl.at(i)++; gl += RG.sum(si) - RG.sum(Girl.at(i)); RG.add(Girl.at(i),1); } return gl; } vector<vector<ll>> mat(vector<vector<ll>> a, vector<vector<ll>> b) { assert(a.at(0).size() == b.size()); int l = a.size(),m = b.size(),n = b.at(0).size(); vector<vector<ll>> c(l,vector<ll>(n,0)); for (int i = 0; i < l; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < m; k++) { c.at(i).at(j) += a.at(i).at(k) * b.at(k).at(j) % MOD; c.at(i).at(j) %= MOD; } } } a = c; return c; } vector<vector<ll>> matpower(vector<vector<ll>> a,ll bit) { //この行列は正方行列のみ vector<vector<ll>> ans(a.size(),vector<ll>(a.size())); bool hoge = true; for (int i = 0; i <= 62; i++) { if ((bit >> i) & 1) { if (hoge) { ans = a; hoge = false; } else { ans = mat(ans,a); } } a = mat(a,a); } return ans; } vector<ll> OneHeart(vector<ll> X,vector<ll> Y) { ll denom = 2 * (X[2] * Y[1] - X[1] * Y[2] + X[0] * Y[2] - X[2] * Y[0] + X[1] * Y[0] - X[0] * Y[1]); ll Numer = Y[0] * (X[2] * X[2] + Y[2] * Y[2] - X[1] * X[1] - Y[1] * Y[1]); Numer += Y[1] * (X[0] * X[0] + Y[0] * Y[0] - X[2] * X[2] - Y[2] * Y[2]); Numer += Y[2] * (X[1] * X[1] + Y[1] * Y[1] - X[0] * X[0] - Y[0] * Y[0]); if (denom == 0) { vector<ll> Cor{-INF,-INF}; return Cor; } Numer *= -1; if (denom * Numer >= 0) { chmax(denom,-denom); chmax(Numer,-Numer); } else { chmax(denom,-denom); chmin(Numer,-Numer); } vector<ll> Cor{Numer,denom}; return Cor; } vector<vector<ll>> OutHeart(vector<ll> X, vector<ll> Y){ vector<vector<ll>> OutH(2,vector<ll>(2)); OutH.at(0) = OneHeart(X,Y); OutH.at(1) = OneHeart(Y,X); return OutH; } struct edge {ll to,cost;}; template<class T> using Graph = vector<vector<T>>; const ll MOD = 1e9+7; /* random_device seed; default_random_engine engine(seed()); uniform_int_distribution<ll> num(x,y); */ int main(){ Sugsugar; COMinit(); ll N, K; cin >> N >> K; ll sum = 1; for (ll i = 1; i <= N; i++) { sum *= K - i + 1; sum %= MOD; sum *= Expo(i, MOD - 2); sum %= MOD; } if (K < N) sum = 0; ll ans = 0; bool flag = false; for (ll i = 0; i <= N; i++) { ans += sum * COM(N - 1, i) % MOD; ans %= MOD; if (flag || N <= K) { sum *= K + i + 1; sum %= MOD; sum *= Expo(K - N + i + 1, MOD - 2); sum %= MOD; } else if (K + i + 1 == N && !flag) { flag = true; sum = 1; } } cout << ans << endl; return 0; }