結果
問題 | No.2229 Treasure Searching Rod (Hard) |
ユーザー | tsugutsugu |
提出日時 | 2023-02-25 13:42:20 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 203 ms / 2,000 ms |
コード長 | 2,540 bytes |
コンパイル時間 | 1,787 ms |
コンパイル使用メモリ | 169,764 KB |
実行使用メモリ | 17,408 KB |
最終ジャッジ日時 | 2024-09-13 11:13:16 |
合計ジャッジ時間 | 7,496 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
15,240 KB |
testcase_01 | AC | 6 ms
15,240 KB |
testcase_02 | AC | 5 ms
15,232 KB |
testcase_03 | AC | 6 ms
15,360 KB |
testcase_04 | AC | 7 ms
15,232 KB |
testcase_05 | AC | 6 ms
15,232 KB |
testcase_06 | AC | 6 ms
15,360 KB |
testcase_07 | AC | 181 ms
17,280 KB |
testcase_08 | AC | 203 ms
17,292 KB |
testcase_09 | AC | 176 ms
17,292 KB |
testcase_10 | AC | 180 ms
17,408 KB |
testcase_11 | AC | 175 ms
17,408 KB |
testcase_12 | AC | 103 ms
16,072 KB |
testcase_13 | AC | 102 ms
16,196 KB |
testcase_14 | AC | 91 ms
16,128 KB |
testcase_15 | AC | 200 ms
17,280 KB |
testcase_16 | AC | 200 ms
17,292 KB |
testcase_17 | AC | 197 ms
17,296 KB |
testcase_18 | AC | 200 ms
17,280 KB |
testcase_19 | AC | 199 ms
17,280 KB |
testcase_20 | AC | 197 ms
17,280 KB |
testcase_21 | AC | 198 ms
17,408 KB |
testcase_22 | AC | 199 ms
17,280 KB |
testcase_23 | AC | 81 ms
15,872 KB |
testcase_24 | AC | 105 ms
16,256 KB |
testcase_25 | AC | 120 ms
16,384 KB |
testcase_26 | AC | 51 ms
15,488 KB |
testcase_27 | AC | 21 ms
15,360 KB |
testcase_28 | AC | 163 ms
17,024 KB |
testcase_29 | AC | 154 ms
16,780 KB |
testcase_30 | AC | 27 ms
15,616 KB |
testcase_31 | AC | 45 ms
15,368 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; // const int mod = 1000000007; struct modint { long long a = 0; modint(long long x = 0) {while (x < 0) x += mod; a = x % mod;} modint(const modint &r) {a = r.a;} modint operator -(){return modint(-a);} modint operator +(const modint &r) {return modint(*this) += r;} modint operator -(const modint &r) {return modint(*this) -= r;} modint operator *(const modint &r) {return modint(*this) *= r;} modint &operator +=(const modint &r) { a += r.a; if(a >= mod) a -= mod; return *this; } modint &operator -=(const modint &r) { a -= r.a; if(a < 0) a += mod; return *this; } modint &operator *=(const modint &r) { a = a * r.a % mod; return *this; } modint pow(long long r) const { if (!r) return 1; modint x = pow(r >> 1); x *= x; if (r & 1) x *= *this; return x; } modint inverse() const { return pow(mod - 2); } modint& operator/=(const modint r) { return (*this) *= r.inverse(); } modint operator/(const modint r) const { modint res(*this); return res /= r; } }; istream &operator>>(istream &is, modint &x) { long long t; is >> t; x = t; return is; } ostream &operator<<(ostream &os, const modint& x) { return os << x.a; } const int MAX = 500044; modint fac[MAX], inv[MAX], finv[MAX]; void cominit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for(int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * modint(i); inv[i] = - inv[mod % i] * modint(mod / i); finv[i] = finv[i - 1] * inv[i]; } } modint Com(long long n, long long k) { if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * finv[k] * finv[n - k]; } modint Per(long long n, long long k) { if(n < k) return 0; if(n < 0 || k < 0) return 0; return fac[n] * finv[n - k]; } using Mint = modint; int main() { int h, w, k; cin >> h >> w >> k; vector<int> x(k), y(k), v(k); for (int i = 0; i < k; i++) { cin >> x[i] >> y[i] >> v[i]; } Mint ans = 0; for (int i = 0; i < k; i++) { long long A = max(1, x[i] - y[i] + 1); Mint B = (A + x[i]) * (x[i] - A + 1) / 2; long long C = max(1, x[i] - (w - y[i])); Mint D = (C + x[i]) * (x[i] - C + 1) / 2; ans += Mint(v[i]) * Mint(B + D - x[i]); } cout << ans << endl; }