結果

問題 No.1035 Color Box
ユーザー imoni_kawaiiimoni_kawaii
提出日時 2020-06-11 20:08:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 2,635 bytes
コンパイル時間 2,150 ms
コンパイル使用メモリ 203,276 KB
実行使用メモリ 34,680 KB
最終ジャッジ日時 2023-09-06 08:35:54
合計ジャッジ時間 6,086 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
34,436 KB
testcase_01 AC 33 ms
34,328 KB
testcase_02 AC 33 ms
34,328 KB
testcase_03 AC 37 ms
34,384 KB
testcase_04 AC 36 ms
34,312 KB
testcase_05 AC 33 ms
34,432 KB
testcase_06 AC 32 ms
34,472 KB
testcase_07 AC 32 ms
34,472 KB
testcase_08 AC 71 ms
34,336 KB
testcase_09 AC 46 ms
34,140 KB
testcase_10 AC 31 ms
34,636 KB
testcase_11 AC 32 ms
34,500 KB
testcase_12 AC 33 ms
34,192 KB
testcase_13 AC 63 ms
34,316 KB
testcase_14 AC 71 ms
34,244 KB
testcase_15 AC 79 ms
34,516 KB
testcase_16 AC 32 ms
34,264 KB
testcase_17 AC 33 ms
34,388 KB
testcase_18 AC 34 ms
34,384 KB
testcase_19 AC 76 ms
34,316 KB
testcase_20 AC 32 ms
34,192 KB
testcase_21 AC 31 ms
34,480 KB
testcase_22 AC 32 ms
34,436 KB
testcase_23 AC 30 ms
34,448 KB
testcase_24 AC 32 ms
34,680 KB
testcase_25 AC 32 ms
34,196 KB
testcase_26 AC 32 ms
34,136 KB
testcase_27 AC 32 ms
34,464 KB
testcase_28 AC 33 ms
34,220 KB
testcase_29 AC 32 ms
34,640 KB
testcase_30 AC 32 ms
34,484 KB
testcase_31 AC 34 ms
34,132 KB
testcase_32 AC 34 ms
34,320 KB
testcase_33 AC 32 ms
34,448 KB
testcase_34 AC 32 ms
34,144 KB
testcase_35 AC 32 ms
34,332 KB
testcase_36 AC 32 ms
34,460 KB
testcase_37 AC 32 ms
34,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

constexpr int MAX_N = 2010101;
constexpr int MOD = 1e9+7;
//constexpr int MOD = 998244353;

struct mint {
long long x;
  mint(long long x = 0) noexcept : x((x%MOD + MOD) % MOD) {}

  // basis
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) noexcept { if((x += a.x) >= MOD) x -= MOD; return *this; }
  mint& operator-=(const mint a) noexcept { if((x += MOD-a.x) >= MOD) x -= MOD; return *this; }
  mint& operator*=(const mint a) noexcept { (x *= a.x) %= MOD; return *this; }
  mint operator+(const mint a) const noexcept { return mint(*this) += a; }
  mint operator-(const mint a) const noexcept { return mint(*this) -= a; }
  mint operator*(const mint a) const noexcept { return mint(*this) *= a; }
  mint mpow(long long t) const noexcept {
    if(!t) return 1;
    mint a = mpow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const noexcept { return mpow(MOD-2); }
  mint& operator/=(const mint a) noexcept { return *this *= a.inv(); }
  mint operator/(const mint a) const noexcept { return mint(*this) /= a; }

  // comparison
  bool operator==(const mint &a) const noexcept { return this->x == a.x; }
  bool operator!=(const mint &a) const noexcept { return this->x != a.x; }

  // I/O stream
  friend istream& operator>>(istream& is, mint& a) noexcept { return is >> a.x; }
  friend ostream& operator<<(ostream& os, const mint& a) noexcept { return os << a.x; }
};
// additional
mint mpow(const long long &a, ll n) noexcept { return mint(a).mpow(n); }
mint mpow(const mint &a, ll n) noexcept { return a.mpow(n); }

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n+1), ifact(n+1) {
    assert(n < MOD);
    fact[0] = 1;
    for(int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for(int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if(k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} com(MAX_N);


int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  mint ans = mpow(m, n);
  REP(i, 1, m+1) {
    ans += mpow(-1, i)*com(m, i)*mpow(m-i, n);
  }
  cout << ans << '\n';
  return 0;
}
0