結果

問題 No.1554 array_and_me
ユーザー SSRSSSRS
提出日時 2021-06-18 21:53:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,771 bytes
コンパイル時間 1,902 ms
コンパイル使用メモリ 177,632 KB
実行使用メモリ 6,956 KB
最終ジャッジ日時 2023-09-04 22:52:09
合計ジャッジ時間 5,859 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 22 ms
4,380 KB
testcase_02 AC 23 ms
4,380 KB
testcase_03 AC 23 ms
4,384 KB
testcase_04 AC 23 ms
4,380 KB
testcase_05 AC 23 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 49 ms
5,024 KB
testcase_12 AC 49 ms
4,824 KB
testcase_13 AC 49 ms
4,828 KB
testcase_14 AC 49 ms
4,876 KB
testcase_15 AC 49 ms
5,024 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 50 ms
4,380 KB
testcase_37 AC 49 ms
4,380 KB
testcase_38 AC 50 ms
4,380 KB
testcase_39 AC 49 ms
4,384 KB
testcase_40 AC 50 ms
4,380 KB
testcase_41 AC 22 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long modpow(long long a, long long b){
	long long ans = 1;
	while (b > 0){
		if (b % 2 == 1){
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		b /= 2;
	}
	return ans;
}
long long modinv(long long a){
	return modpow(a, MOD - 2);
}
vector<long long> mf = {1};
vector<long long> mfi = {1};
long long modfact(int n){
	if (mf.size() > n){
		return mf[n];
	} else {
		for (int i = mf.size(); i <= n; i++){
			long long next = mf.back() * i % MOD;
			mf.push_back(next);
			mfi.push_back(modinv(next));
		}
		return mf[n];
	}
}
long long modfactinv(int n){
	if (mfi.size() > n){
		return mfi[n];
	} else {
		return modinv(modfact(n));
	}
}
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int j = 0; j < N; j++){
      cin >> A[j];
      A[j]++;
    }
    int S = 0;
    for (int j = 0; j < N; j++){
      S += A[j];
    }
    vector<int> q(N), r(N);
    for (int j = 0; j < N; j++){
      q[j] = A[j] * K / S;
      r[j] = A[j] * K % S;
    }
    int sum = 0;
    for (int j = 0; j < N; j++){
      sum += q[j];
    }
    int R = K - sum;
    vector<pair<int, int>> P(N);
    for (int j = 0; j < N; j++){
      P[j] = make_pair(r[j], j);
    }
    sort(P.begin(), P.end(), greater<pair<int, int>>());
    for (int j = 0; j < R; j++){
      q[P[j].second]++;
    }
    long long ans = 1;
    S -= N;
    for (int j = 0; j < N; j++){
      A[j]--;
      long long p = A[j] * modinv(S % MOD) % MOD;
      ans *= modpow(p, q[j]);
      ans %= MOD;
    }
    ans *= modfact(K);
    ans %= MOD;
    for (int j = 0; j < N; j++){
      ans *= modfactinv(q[j]);
      ans %= MOD;
    }
    cout << ans << endl;
  }
}
0