結果
| 問題 | 
                            No.391 CODING WAR
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2020-07-02 23:38:37 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 110 ms / 2,000 ms | 
| コード長 | 2,263 bytes | 
| コンパイル時間 | 1,009 ms | 
| コンパイル使用メモリ | 100,580 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-09-15 08:43:25 | 
| 合計ジャッジ時間 | 2,415 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 16 | 
ソースコード
#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;
}