結果

問題 No.3698 くじ引きでチーム分け
コンテスト
ユーザー yuki2006
提出日時 2026-08-27 21:35:45
言語 JavaScript
(node v26.7.0 + ACL)
コンパイル:
true
実行:
node _filename_ ONLINE_JUDGE
結果
AC  
実行時間 174 ms / 2,000 ms
+ 243µs
コード長 795 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4 ms
コンパイル使用メモリ 6,528 KB
実行使用メモリ 130,124 KB
最終ジャッジ日時 2026-09-09 20:50:55
合計ジャッジ時間 3,802 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

const MOD = 998244353n;
const d = require('fs').readFileSync(0, 'utf8').split(/\s+/);
let p = 0;
const n = BigInt(d[p++]), k = BigInt(d[p++]);
const N = Number(n);
const A = new Array(N);
let sumA = 0n, sumB = 0n, sumAB = 0n;
for (let i = 0; i < N; i++) { A[i] = BigInt(d[p++]) % MOD; sumA = (sumA + A[i]) % MOD; }
for (let i = 0; i < N; i++) {
  const b = BigInt(d[p++]) % MOD;
  sumB = (sumB + b) % MOD;
  sumAB = (sumAB + A[i] * b) % MOD;
}
const power = (a, e) => { let r = 1n; a %= MOD; while (e > 0n) { if (e & 1n) r = r * a % MOD; a = a * a % MOD; e >>= 1n; } return r; };
const teamSize = n / k;
const prob = (teamSize - 1n + MOD) % MOD * power((n - 1n) % MOD, MOD - 2n) % MOD;
const total = ((sumA * sumB % MOD) - sumAB % MOD + MOD) % MOD;
console.log((prob * total % MOD).toString());
0