結果

問題 No.2225 Treasure Searching Rod (Easy)
ユーザー みここみここ
提出日時 2023-02-24 21:28:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 3,236 bytes
コンパイル時間 529 ms
コンパイル使用メモリ 69,380 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-11 05:49:43
合計ジャッジ時間 1,885 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

template <int MOD>
struct static_modint
{
    using mint = static_modint;

public:
    int val;

    static_modint() : val(0) {}

    static_modint(long long v)
    {
        if (std::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;
    }

private:
    static constexpr int mod()
    {
        return MOD;
    }
};

using mint = static_modint<998244353>;

int main()
{
    int h, w, k;
    cin >> h >> w >> k;
    mint a[52][52];
    for (int i = 0; i < k; i++)
    {
        int x, y;
        mint v;
        cin >> x >> y >> v;
        x--;
        y--;
        a[x][y] = v;
    }
    mint ans = 0;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            for (int x = 0; x < h; x++)
            {
                for (int y = 0; y < w; y++)
                {
                    if (x + y >= i + j && x - y >= i - j)
                    {
                        ans += a[x][y];
                    }
                }
            }
        }
    }
    cout << ans << endl;
}
0