結果

問題 No.2585 How many "Who is Santa?"
ユーザー fdironiafdironia
提出日時 2023-12-15 06:25:58
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 215 ms / 1,225 ms
コード長 827 bytes
コンパイル時間 700 ms
コンパイル使用メモリ 77,292 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-15 06:26:03
合計ジャッジ時間 4,385 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 34 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 215 ms
6,676 KB
testcase_05 AC 190 ms
6,676 KB
testcase_06 AC 206 ms
6,676 KB
testcase_07 AC 162 ms
6,676 KB
testcase_08 AC 36 ms
6,676 KB
testcase_09 AC 159 ms
6,676 KB
testcase_10 AC 178 ms
6,676 KB
testcase_11 AC 168 ms
6,676 KB
testcase_12 AC 111 ms
6,676 KB
testcase_13 AC 21 ms
6,676 KB
testcase_14 AC 71 ms
6,676 KB
testcase_15 AC 139 ms
6,676 KB
testcase_16 AC 100 ms
6,676 KB
testcase_17 AC 106 ms
6,676 KB
testcase_18 AC 81 ms
6,676 KB
testcase_19 AC 201 ms
6,676 KB
testcase_20 AC 146 ms
6,676 KB
testcase_21 AC 78 ms
6,676 KB
testcase_22 AC 132 ms
6,676 KB
testcase_23 AC 30 ms
6,676 KB
testcase_24 AC 11 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0