結果
| 問題 |
No.2585 How many "Who is Santa?"
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-15 06:25:58 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 216 ms / 1,225 ms |
| コード長 | 827 bytes |
| コンパイル時間 | 741 ms |
| コンパイル使用メモリ | 78,132 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-27 06:02:06 |
| 合計ジャッジ時間 | 4,195 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#include <iostream>
using namespace std;
constexpr int Z = 998244353;
int main() {
int n;
cin >> n;
// case 1: for at least 2, a: 1 b, c: 1 b
// b: 1 !b, other: 1 b or 0 !b
// n*((n-1)^(n-1)-(n-2)^(n-1)-(n-1)*(n-2)^(n-2))*(n-1)
// case 2: a: 1 b, b: 1 c, other: 0 !b
// n*(n-1)*(n-2)*(n-2)^(n-2)
// case 3: a: 1 b, b: 1 a,
// other: 0 !b, for at least 1, 0 a
// n*(n-1)*((n-2)^(n-2)-(n-3)^(n-2))
// case 4: b: 1 a
// other: 0 !b
// n*(n-1)*(n-2)^(n-1)
// add: n*(n-1)^(n-1)-n*(n-1)*(n-3)^(n-2)
int p1 = n;
for (int i = 0; i < n; i++) {
p1 = 1ll * p1 * (n - 1) % Z;
}
int p2 = 1ll * n * (n - 1) % Z;
for (int i = 0; i < n - 2; i++) {
p2 = 1ll * p2 * (n - 3) % Z;
}
cout << (p1 - p2 + Z) % Z << endl;
return 0;
}