結果

問題 No.2225 Treasure Searching Rod (Easy)
ユーザー CoCo_Japan_panCoCo_Japan_pan
提出日時 2023-02-24 22:15:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,038 bytes
コンパイル時間 2,257 ms
コンパイル使用メモリ 201,212 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-11 06:23:56
合計ジャッジ時間 3,400 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// 提出時にassertはオフ
#ifndef DEBUG
#ifndef NDEBUG
#define NDEBUG
#endif
#endif

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;

#define ALL(x) (x).begin(), (x).end()
template <class T> using vec = vector<T>;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll H, W, K;
    cin >> H >> W >> K;
    mint ans = 0;
    for(ll i = 0; i < K; i++){
        ll x, y, v;
        cin >> x >> y >> v;
        mint cnt = 0;
        cnt += x;
        ll abs_1 = x - min(y - 1, W - y);
        if(abs_1 <= 1){
            // x-1~1の和 * 2
            cnt += x * (x - 1);
        } else {
            // x-1~abs_1の和 * 2 + (abs_1 - 1 ~ abs_2の和)
            ll abs_2 = max((ll)1, x - max(y - 1, W - y));
            cnt += (x - 1 + abs_1) * (x - 1 - abs_1 + 1);
            cnt += (abs_1 - 1 + abs_2) * (abs_1 - 1 - abs_2 + 1) / 2;
        }
        ans += cnt * v;
    }
    cout << ans.val() << "\n";
}
0