結果

問題 No.2113 Distance Sequence 1.5
ユーザー みここみここ
提出日時 2022-12-11 22:18:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,523 bytes
コンパイル時間 605 ms
コンパイル使用メモリ 70,900 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 16:57:26
合計ジャッジ時間 1,476 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 WA -
testcase_21 AC 1 ms
5,376 KB
testcase_22 WA -
testcase_23 AC 2 ms
5,376 KB
testcase_24 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
typedef long long ll;

const int MOD = 998244353;

struct mint
{
    int val;

    mint() : val(0) {}

    mint(long long v)
    {
        if (abs(v) >= MOD)
        {
            v %= MOD;
        }
        if (v < 0)
        {
            v += MOD;
        }
        val = v;
    }

    mint &operator++()
    {
        val++;
        if (val == MOD)
        {
            val = 0;
        }
        return *this;
    }

    mint &operator--()
    {
        if (val == 0)
        {
            val = MOD;
        }
        val--;
        return *this;
    }

    mint &operator+=(const mint &x)
    {
        val += x.val;
        if (val >= MOD)
        {
            val -= MOD;
        }
        return *this;
    }

    mint &operator-=(const mint &x)
    {
        val -= x.val;
        if (val < 0)
        {
            val += MOD;
        }
        return *this;
    }

    mint &operator*=(const mint &x)
    {
        val = (int)((long long)val * x.val % MOD);
        return *this;
    }

    mint &operator/=(const mint &x)
    {
        *this *= x.inv();
        return *this;
    }

    mint operator-()
    {
        return mint() - *this;
    }

    mint pow(long long n) const
    {
        mint x = 1, r = *this;
        while (n)
        {
            if (n & 1)
            {
                x *= r;
            }
            r *= r;
            n >>= 1;
        }
        return x;
    }

    mint inv() const
    {
        return pow(MOD - 2);
    }

    friend mint operator+(const mint &x, const mint &y)
    {
        return mint(x) += y;
    }

    friend mint operator-(const mint &x, const mint &y)
    {
        return mint(x) -= y;
    }

    friend mint operator*(const mint &x, const mint &y)
    {
        return mint(x) *= y;
    }

    friend mint operator/(const mint &x, const mint &y)
    {
        return mint(x) /= y;
    }

    friend bool operator==(const mint &x, const mint &y)
    {
        return x.val == y.val;
    }

    friend bool operator!=(const mint &x, const mint &y)
    {
        return x.val != y.val;
    }

    friend std::ostream &operator<<(std::ostream &os, const mint &x)
    {
        return os << x.val;
    }

    friend std::istream &operator>>(std::istream &is, mint &x)
    {
        long long v;
        is >> v;
        x = mint(v);
        return is;
    }
};

int main()
{
    ll n;
    mint m, k;
    cin >> n >> m >> k;
    n *= 2;
    cout << (k.pow(n) - (k - 1).pow(n)) * (m - k) + k.pow(n) << endl;
}
0