結果

問題 No.391 CODING WAR
ユーザー snbnsnbn
提出日時 2020-07-02 23:38:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 2,263 bytes
コンパイル時間 1,008 ms
コンパイル使用メモリ 100,144 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-10-13 11:46:06
合計ジャッジ時間 3,190 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 115 ms
4,376 KB
testcase_10 AC 105 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,372 KB
testcase_13 AC 110 ms
4,508 KB
testcase_14 AC 89 ms
4,504 KB
testcase_15 AC 103 ms
4,372 KB
testcase_16 AC 60 ms
4,376 KB
testcase_17 AC 70 ms
4,376 KB
testcase_18 AC 48 ms
4,372 KB
testcase_19 AC 49 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

#define chmax(a, b) (a) = max(a, b)
#define chmin(a, b) (a) = min(a, b)

template <int64_t MOD>
class Modint {
  using Self = Modint<MOD>;

  int64_t m_value;

 public:
  Modint() : m_value(0) {}
  Modint(int64_t value) : m_value((value % MOD + MOD) % MOD) {}
  Self pow(int64_t e) const {
    if (e == 0) {
      return (Self)1;
    } else if (e % 2 == 0) {
      return ((*this) * (*this)).pow(e / 2);
    } else {
      return (*this).pow(e - 1) * (*this);
    }
  }
  Self inv() const { return pow(MOD - 2); }
  Self& operator=(const Self& rh) {
    m_value = rh.m_value;
    return *this;
  }
  Self operator-() const { return Self(-m_value); }
  Self operator+(const Self& other) const {
    return Self(m_value + other.m_value);
  }
  Self operator-(const Self& other) const {
    return Self(m_value - other.m_value);
  }
  Self operator*(const Self& other) const {
    return Self(m_value * other.m_value);
  }
  Self operator/(const Self& other) const { return (*this) * other.inv(); }
  Self& operator+=(const Self& rh) { return (*this) = (*this) + rh; }
  Self& operator-=(const Self& rh) { return (*this) = (*this) - rh; }
  Self& operator*=(const Self& rh) { return (*this) = (*this) * rh; }
  Self& operator/=(const Self& rh) { return (*this) = (*this) / rh; }
  int64_t value() const { return m_value; }
};

int main() {
  int64_t N, M;
  cin >> N >> M;

  if (N < M) {
    cout << 0 << endl;
    return 0;
  }

  using Mint = Modint<1'000'000'007>;
  vector<Mint> fact(M + 1);
  fact[0] = 1;
  rep(i, M) { fact[i + 1] = fact[i] * (i + 1); }

  Mint result = 0;
  irep(i, M) {
    Mint term = Mint(-1).pow(i) * fact[M] / (fact[i] * fact[M - i]) *
                Mint(M - i).pow(N);
    result += term;
  }
  cout << result.value() << endl;
  return 0;
}
0