結果
問題 | No.2229 Treasure Searching Rod (Hard) |
ユーザー |
|
提出日時 | 2023-02-24 22:15:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 61 ms / 2,000 ms |
コード長 | 1,038 bytes |
コンパイル時間 | 2,023 ms |
コンパイル使用メモリ | 196,116 KB |
最終ジャッジ日時 | 2025-02-10 21:17:59 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
// 提出時に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の和 * 2cnt += 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";}