結果

問題 No.1552 Simple Dice Game
ユーザー naskyanaskya
提出日時 2021-06-18 23:21:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 307 ms / 2,500 ms
コード長 691 bytes
コンパイル時間 730 ms
コンパイル使用メモリ 78,144 KB
実行使用メモリ 7,112 KB
最終ジャッジ日時 2023-09-05 00:15:10
合計ジャッジ時間 5,270 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 304 ms
7,052 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 230 ms
6,176 KB
testcase_10 AC 269 ms
6,728 KB
testcase_11 AC 278 ms
6,660 KB
testcase_12 AC 80 ms
4,380 KB
testcase_13 AC 230 ms
6,136 KB
testcase_14 AC 134 ms
4,920 KB
testcase_15 AC 169 ms
5,088 KB
testcase_16 AC 25 ms
4,380 KB
testcase_17 AC 41 ms
4,384 KB
testcase_18 AC 215 ms
5,928 KB
testcase_19 AC 305 ms
6,988 KB
testcase_20 AC 306 ms
7,100 KB
testcase_21 AC 299 ms
7,112 KB
testcase_22 AC 305 ms
6,936 KB
testcase_23 AC 307 ms
6,924 KB
権限があれば一括ダウンロードができます

ソースコード

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