結果
問題 | No.2229 Treasure Searching Rod (Hard) |
ユーザー | t98slider |
提出日時 | 2023-02-24 22:55:27 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 4,314 bytes |
コンパイル時間 | 1,668 ms |
コンパイル使用メモリ | 168,820 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-13 05:57:43 |
合計ジャッジ時間 | 4,152 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 52 ms
6,940 KB |
testcase_08 | AC | 57 ms
6,944 KB |
testcase_09 | AC | 53 ms
6,940 KB |
testcase_10 | AC | 52 ms
6,940 KB |
testcase_11 | AC | 51 ms
6,940 KB |
testcase_12 | AC | 29 ms
6,940 KB |
testcase_13 | AC | 29 ms
6,940 KB |
testcase_14 | AC | 27 ms
6,944 KB |
testcase_15 | AC | 58 ms
6,940 KB |
testcase_16 | AC | 58 ms
6,940 KB |
testcase_17 | AC | 58 ms
6,940 KB |
testcase_18 | AC | 58 ms
6,940 KB |
testcase_19 | AC | 58 ms
6,940 KB |
testcase_20 | AC | 58 ms
6,940 KB |
testcase_21 | AC | 58 ms
6,940 KB |
testcase_22 | AC | 58 ms
6,940 KB |
testcase_23 | AC | 24 ms
6,940 KB |
testcase_24 | AC | 30 ms
6,944 KB |
testcase_25 | AC | 35 ms
6,944 KB |
testcase_26 | AC | 15 ms
6,944 KB |
testcase_27 | AC | 6 ms
6,940 KB |
testcase_28 | AC | 47 ms
6,944 KB |
testcase_29 | AC | 45 ms
6,940 KB |
testcase_30 | AC | 8 ms
6,940 KB |
testcase_31 | AC | 13 ms
6,944 KB |
ソースコード
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define codefor int test;cin>>test;while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) using namespace std; using ll = long long; template<class T> using rpriority_queue = priority_queue<T, vector<T>, greater<T>>; template<class T> istream& operator>>(istream& is, vector<T>& vec) {for(T& x : vec)is >> x;return is;} template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) {if(vec.empty())return os;os << vec[0];for(auto it = vec.begin(); ++it!= vec.end();)os << ' ' << *it;return os;} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){cin >> head;in(tail...);} void out(){cout << '\n';} template<class T>void out(const T& a){cout << a << '\n';} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){cout << head << ' ';out(tail...);} const int INF = 1 << 30; const long long INF2 = 1ll << 60; template<class T> void chmax(T &a,const T b){if(b>a)a=b;} template<class T> void chmin(T &a,const T b){if(b<a)a=b;} template<const unsigned int MOD> struct prime_modint { using mint = prime_modint; unsigned int v; prime_modint() : v(0) {} prime_modint(unsigned int a) { a %= MOD; v = a; } prime_modint(int a) { a %= (int)(MOD); if(a < 0)a += MOD; v = a; } prime_modint(long long a) { a %= (int)(MOD); if(a < 0)a += MOD; v = a; } static constexpr int mod() { return MOD; } mint& operator++() {v++; if(v == MOD)v = 0; return *this;} mint& operator--() {if(v == 0)v = MOD; v--; return *this;} mint operator++(int) { mint result = *this; ++*this; return result; } mint operator--(int) { mint result = *this; --*this; return result; } mint& operator+=(const mint& rhs) { v += rhs.v; if(v >= MOD) v -= MOD; return *this; } mint& operator-=(const mint& rhs) { if(v < rhs.v) v += MOD; v -= rhs.v; return *this; } mint& operator*=(const mint& rhs) { v = (unsigned int)((unsigned long long)(v) * rhs.v % MOD); return *this; } mint& operator/=(const mint& rhs) { return *this = *this * rhs.inv(); } mint operator+() const { return *this; } mint operator-() const { return mint() - *this; } mint pow(long long n) const { assert(0 <= n); mint r = 1, x = *this; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } mint inv() const { assert(v); return pow(MOD - 2); } friend mint operator+(const mint& lhs, const mint& rhs) { return mint(lhs) += rhs; } friend mint operator-(const mint& lhs, const mint& rhs) { return mint(lhs) -= rhs; } friend mint operator*(const mint& lhs, const mint& rhs) { return mint(lhs) *= rhs; } friend mint operator/(const mint& lhs, const mint& rhs) { return mint(lhs) /= rhs; } friend bool operator==(const mint& lhs, const mint& rhs) { return (lhs.v == rhs.v); } friend bool operator!=(const mint& lhs, const mint& rhs) { return (lhs.v != rhs.v); } friend std::ostream& operator << (std::ostream &os, const mint& rhs) noexcept { return os << rhs.v; } }; //using mint = prime_modint<1000000007>; using mint = prime_modint<998244353>; //等差数列の和を求める(初項,末項,項数) long long int arith_sum2(long long int a,long long int l,long long int n){ return n * (a + l) / 2; } int main(){ ios::sync_with_stdio(false); cin.tie(0); LL(h, w, k); ll y, x, v; mint ans; for(int i = 0; i < k; i++){ cin >> y >> x >> v; mint d; d += mint(v) * y; if(x > 1){ ll n = x - 1 + min(0ll, y - x); ll s = max(0ll, y - x) + 1; d += mint(v) * arith_sum2(s, y - 1, n); } if(x + 1 <= w){ ll n = w - x + min(0ll, y + x - (w + 1)); ll s = max(0ll, y + x - (w + 1)) + 1; d += mint(v) * arith_sum2(s, y - 1, n); } ans += d; } out(ans); }