結果
問題 | No.1035 Color Box |
ユーザー | knshnb |
提出日時 | 2020-04-24 21:49:06 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,633 bytes |
コンパイル時間 | 2,204 ms |
コンパイル使用メモリ | 209,204 KB |
実行使用メモリ | 11,200 KB |
最終ジャッジ日時 | 2024-10-15 02:41:47 |
合計ジャッジ時間 | 3,892 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 24 ms
10,912 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 16 ms
10,892 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 23 ms
10,864 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 17 ms
10,932 KB |
testcase_12 | WA | - |
testcase_13 | AC | 22 ms
10,960 KB |
testcase_14 | AC | 22 ms
10,896 KB |
testcase_15 | AC | 24 ms
10,932 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 24 ms
11,020 KB |
testcase_20 | WA | - |
testcase_21 | AC | 16 ms
10,860 KB |
testcase_22 | AC | 16 ms
10,888 KB |
testcase_23 | AC | 16 ms
11,016 KB |
testcase_24 | AC | 17 ms
10,988 KB |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 16 ms
10,924 KB |
testcase_29 | AC | 16 ms
10,896 KB |
testcase_30 | WA | - |
testcase_31 | AC | 16 ms
10,928 KB |
testcase_32 | AC | 16 ms
10,932 KB |
testcase_33 | AC | 16 ms
10,956 KB |
testcase_34 | AC | 16 ms
10,956 KB |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | AC | 16 ms
10,868 KB |
ソースコード
#include <bits/stdc++.h> // clang-format off using Int = long long; #define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io; #ifndef _MY_DEBUG #define dump(...) #endif // clang-format on /** * author: knshnb * created: Fri Apr 24 21:46:19 JST 2020 **/ template <class T> T pow(T x, int n, const T UNION = 1) { T ret = UNION; while (n) { if (n & 1) ret *= x; x *= x; n >>= 1; } return ret; } /// @docs src/Math/ModInt.md template <int Mod> struct ModInt { int x; static int runtime_mod; static std::unordered_map<int, int> to_inv; // テンプレート引数が負のときは実行時ModInt static int mod() { return Mod < 0 ? runtime_mod : Mod; } static void set_runtime_mod(int mod) { static_assert(Mod < 0, "template parameter Mod must be negative for runtime ModInt"); runtime_mod = mod; to_inv.clear(); } ModInt() : x(0) {} ModInt(long long x_) { if ((x = x_ % mod() + mod()) >= mod()) x -= mod(); } ModInt& operator+=(ModInt rhs) { if ((x += rhs.x) >= mod()) x -= mod(); return *this; } ModInt& operator*=(ModInt rhs) { x = (unsigned long long)x * rhs.x % mod(); return *this; } ModInt& operator-=(ModInt rhs) { if ((x -= rhs.x) < 0) x += mod(); return *this; } ModInt& operator/=(ModInt rhs) { x = (unsigned long long)x * rhs.inv().x % mod(); return *this; } ModInt operator-() const { return -x < 0 ? mod() - x : -x; } ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; } ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; } ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; } ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; } bool operator==(ModInt rhs) const { return x == rhs.x; } bool operator!=(ModInt rhs) const { return x != rhs.x; } ModInt inv() const { return to_inv.count(this->x) ? to_inv[this->x] : (to_inv[this->x] = pow(*this, mod() - 2).x); } friend std::ostream& operator<<(std::ostream& s, ModInt<Mod> a) { s << a.x; return s; } friend std::istream& operator>>(std::istream& s, ModInt<Mod>& a) { long long tmp; s >> tmp; a = ModInt<Mod>(tmp); return s; } friend std::string to_string(ModInt<Mod> a) { return std::to_string(a.x); } }; template <int Mod> std::unordered_map<int, int> ModInt<Mod>::to_inv; template <int Mod> int ModInt<Mod>::runtime_mod; #ifndef CALL_FROM_TEST using mint = ModInt<1000000007>; #endif template <class T> struct Combination { std::vector<T> fact, fact_inv; Combination(int n = 1000003) : fact(n + 1, 1), fact_inv(n + 1) { for (int i = 0; i < n; i++) fact[i + 1] = fact[i] * (i + 1); fact_inv[n] = (T)1 / fact[n]; for (int i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1); // for (int i = 0; i < n + 1; i++) assert(fact[i] * fact_inv[i] == 1); } T operator()(int n, int r) { return fact[n] * fact_inv[r] * fact_inv[n - r]; } }; signed main() { Combination<mint> comb; Int n, m; std::cin >> n >> m; mint ans = 0; REP(i, m + 1) { int sign = i % 2 ? -1 : 1; ans += comb(m, i) * pow(mint(i), n) * sign; } std::cout << ans << std::endl; }