結果
| 問題 |
No.2225 Treasure Searching Rod (Easy)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-24 22:15:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 21 ms / 2,000 ms |
| コード長 | 1,038 bytes |
| コンパイル時間 | 2,163 ms |
| コンパイル使用メモリ | 195,156 KB |
| 最終ジャッジ日時 | 2025-02-10 21:18:20 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
// 提出時に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";
}