結果

問題 No.1897 Sum of 2nd Max
ユーザー miscalcmiscalc
提出日時 2022-01-14 13:35:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 1,796 bytes
コンパイル時間 2,352 ms
コンパイル使用メモリ 203,548 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 23:52:15
合計ジャッジ時間 6,832 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 197 ms
4,380 KB
testcase_04 AC 198 ms
4,376 KB
testcase_05 AC 95 ms
4,380 KB
testcase_06 AC 114 ms
4,380 KB
testcase_07 AC 127 ms
4,376 KB
testcase_08 AC 102 ms
4,376 KB
testcase_09 AC 195 ms
4,376 KB
testcase_10 AC 194 ms
4,376 KB
testcase_11 AC 194 ms
4,376 KB
testcase_12 AC 194 ms
4,376 KB
testcase_13 AC 195 ms
4,376 KB
testcase_14 AC 132 ms
4,376 KB
testcase_15 AC 134 ms
4,380 KB
testcase_16 AC 142 ms
4,376 KB
testcase_17 AC 138 ms
4,376 KB
testcase_18 AC 140 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 196 ms
4,380 KB
testcase_31 AC 196 ms
4,380 KB
testcase_32 AC 130 ms
4,380 KB
testcase_33 AC 199 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
using namespace atcoder;
using mint = modint998244353;
//using mint = modint1000000007;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll safemod(ll A, ll M) {return (A % M + M) % M;}
ll divfloor(ll A, ll B) {if (B < 0) {return divfloor(-A, -B);} return (A - safemod(A, B)) / B;}
ll divceil(ll A, ll B) {if (B < 0) {return divceil(-A, -B);} return divfloor(A + B - 1, B);}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

mint sum0(mint a, ll n) // sum[i = 0 to n - 1] a^i
{
  return (1 - a.pow(n)) / (1 - a);
}

mint sum1(mint a, ll n) // sum[i = 0 to n - 1] ia^i
{
  return (sum0(a, n) - 1 - (n - 1) * a.pow(n)) / (1 - a);
}

int main()
{
  ll N, K;
  cin >> N >> K;

  mint ans = 0;
  for (ll x = 1; x <= K; x++)
  {
    /*
    mint tmp0 = 0, tmp1 = 0;
    for (ll i = 0; i < N - 1; i++)
    {
      tmp0 += (N * (K - x) + 1) * mint(x - 1).pow(i) * mint(x).pow(N - i - 2);
      tmp1 += i * mint(x - 1).pow(i) * mint(x).pow(N - i - 2);
    }
    mint tmp = tmp0 + tmp1;
    ans += x * tmp;

    cerr << x << " " << tmp0.val() << " " << tmp1.val() << " " << tmp.val() << endl;
    //*/

    //*
    mint y = mint(x - 1) / mint(x);
    mint tmp0 = (N * (K - x) + 1) * mint(x).pow(N - 2) * sum0(y, N - 1);
    mint tmp1 = mint(x).pow(N - 2) * sum1(y, N - 1);
    mint tmp = tmp0 + tmp1;
    ans += x * tmp;
    //*/

    //cerr << x << " " << tmp0.val() << " " << tmp1.val() << " " << tmp.val() << endl;
  }
  cout << ans.val() << endl;
}
0