Submission #27852261


Source Code Expand

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;

using Fp = modint998244353;

Fp factpow(int n, int k) {
  Fp ret = 1;
  for (int i = 0; i < k; ++i) {
    ret *= n - i;
  }
  return ret;
}

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int& x : A) {
    cin >> x;
  }
  vector<Fp> dp = {1};
  for (int x : A) {
    vector<Fp> next(dp.size() + 1);
    for (int i = 0; i < (int)dp.size(); ++i) {
      next[i] += dp[i];
      next[i + 1] += dp[i] * x;
    }
    dp = move(next);
  }
  Fp ans = 0;
  for (int n = 0; n <= N; ++n) {
    if (N - n <= K) {
      ans += dp[n] * factpow(K, N - n) * Fp(N).pow(K - (N - n));
    }
  }
  cout << (ans / (Fp(N).pow(K))).val() << '\n';
}

Submission Info

Submission Time
Task G - Balls in Boxes
User KoD
Language C++ (GCC 9.2.1)
Score 600
Code Size 784 Byte
Status AC
Exec Time 14 ms
Memory 3676 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 35
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 14 ms 3580 KiB
random_02.txt AC 11 ms 3672 KiB
random_03.txt AC 10 ms 3640 KiB
random_04.txt AC 2 ms 3640 KiB
random_05.txt AC 8 ms 3648 KiB
random_06.txt AC 6 ms 3588 KiB
random_07.txt AC 9 ms 3564 KiB
random_08.txt AC 3 ms 3672 KiB
random_09.txt AC 12 ms 3492 KiB
random_10.txt AC 7 ms 3676 KiB
random_11.txt AC 7 ms 3676 KiB
random_12.txt AC 5 ms 3596 KiB
random_13.txt AC 10 ms 3588 KiB
random_14.txt AC 7 ms 3648 KiB
random_15.txt AC 10 ms 3676 KiB
random_16.txt AC 7 ms 3624 KiB
random_17.txt AC 12 ms 3548 KiB
random_18.txt AC 3 ms 3540 KiB
random_19.txt AC 12 ms 3528 KiB
random_20.txt AC 2 ms 3416 KiB
random_21.txt AC 10 ms 3632 KiB
random_22.txt AC 2 ms 3496 KiB
random_23.txt AC 6 ms 3544 KiB
random_24.txt AC 2 ms 3552 KiB
random_25.txt AC 7 ms 3488 KiB
random_26.txt AC 2 ms 3524 KiB
random_27.txt AC 7 ms 3544 KiB
random_28.txt AC 2 ms 3480 KiB
random_29.txt AC 12 ms 3676 KiB
random_30.txt AC 2 ms 3412 KiB
random_31.txt AC 7 ms 3488 KiB
random_32.txt AC 2 ms 3552 KiB
sample_01.txt AC 2 ms 3512 KiB
sample_02.txt AC 2 ms 3552 KiB
sample_03.txt AC 2 ms 3404 KiB