結果

問題 No.1552 Simple Dice Game
ユーザー naskya
提出日時 2021-06-18 23:21:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 300 ms / 2,500 ms
コード長 691 bytes
コンパイル時間 677 ms
コンパイル使用メモリ 75,448 KB
最終ジャッジ日時 2025-01-22 09:45:34
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/modint>
#include <iostream>
#include <vector>

int main() {
  long long N;
  int M;
  std::cin >> N >> M;

  using mint = atcoder::modint998244353;

  // X[i] = sum(terms of A; A = (N integers between 1 and i (incl.)))
  // Y[i] = sum(terms of A; A = (N integers between M - i + 1 and M (incl.)))
  std::vector<mint> X(M + 2), Y(M + 2);

  mint s = 0;  // s = 1 + 2 + ... + i

  for (int i = 1; i <= M; i++) {
    s += i;
    X[i] = mint(i).pow(N - 1) * N * s;
    Y[i] = mint(i).pow(N) * N * (M + 1) - X[i];
  }

  mint ans = 0;

  for (int i = 1; i <= M; i++) {
    ans += i * (X[i] - X[i - 1]);
    ans -= i * (Y[i] - Y[i + 1]);
  }

  std::cout << ans.val() << "\n";
}
0