結果

問題 No.2225 Treasure Searching Rod (Easy)
ユーザー shoshoshomshoshoshom
提出日時 2023-02-24 21:34:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 2,902 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 202,464 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 05:55:26
合計ジャッジ時間 3,347 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#ifndef SHO_LOCAL
#include <bits/stdc++.h>
#define debug(...) ;
#else
#include "debug.h"
#endif
#define all(x) (x).begin(), (x).end()
#define lb(x, a) lower_bound(all(x), (a)) - (x).begin()
typedef long long ll;
using namespace std;

constexpr const long long _mod = 998244353;
struct mint;
static vector<mint> inv_memo;
static vector<mint> fact_memo;
struct mint {
  using ll = long long;
  ll raw_val;
  mint(ll x = 0) { raw_val = (x % _mod + _mod) % _mod; }
  inline mint operator-() const { return mint(-raw_val); }
  inline mint &operator+=(const mint a) {
    if ((raw_val += a.raw_val) >= _mod)
      raw_val -= _mod;
    return *this;
  }
  inline mint &operator-=(const mint a) {
    if ((raw_val += _mod - a.raw_val) >= _mod)
      raw_val -= _mod;
    return *this;
  }
  inline mint &operator*=(const mint a) {
    (raw_val *= a.raw_val) %= _mod;
    return *this;
  }
  inline mint operator+(const mint a) const { return mint(*this) += a; }
  inline mint operator-(const mint a) const { return mint(*this) -= a; }
  inline mint operator*(const mint a) const { return mint(*this) *= a; }
  inline mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }
  inline mint inv() const {
    if ((int)inv_memo.size() > raw_val) {
      return inv_memo[raw_val];
    }
    return pow(_mod - 2);
  }
  inline mint &operator/=(const mint a) { return *this *= a.inv(); }
  inline mint operator/(const mint a) const { return mint(*this) /= a; }
};
static inline mint factorial(int n) {
  mint res(1);
  for (int i = 2; i <= n; i++) {
    res *= i;
  }
  return res;
}
struct mcombination {
  vector<mint> f, invf;
  mcombination(const int n) : f(n + 1), invf(n + 1) {
    f[0] = 1;
    for (int i = 1; i <= n; ++i)
      f[i] = f[i - 1] * i;
    invf[n] = f[n].inv();
    for (int i = n; i >= 1; --i)
      invf[i - 1] = invf[i] * i;
  }
  inline mint _c(const int n, const int k) const {
    if (k < 0 || k > n)
      return 0;
    return f[n] * invf[k] * invf[n - k];
  }
  inline mint operator()(const int n, const int k) const { return _c(n, k); }
  inline mint h(const int n, const int r) const { return _c(n + r - 1, r); }
};
static inline istream &operator>>(istream &is, mint &a) {
  return is >> a.raw_val;
}
static inline ostream &operator<<(ostream &os, const mint &a) {
  return os << a.raw_val;
}

struct E {
  int x, y, v;
};

int main() {
  iostream::sync_with_stdio(0), cin.tie(0);

  int h, w, k;
  cin >> h >> w >> k;
  vector<E> A;
  for (int i = 0; i < k; i++) {
    int x, y, v;
    cin >> x >> y >> v;
    A.push_back({x, y, v});
  }

  mint ans = 0;
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      for (auto [x, y, v]: A) {
        if (x + y >= i + j && x - y  >= i - j) {
          ans += v;
        }
      }
      
    }
  }
  cout << ans << '\n';
  

  return 0;
}
0