結果

問題 No.2229 Treasure Searching Rod (Hard)
ユーザー umezo
提出日時 2023-02-24 23:01:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 661 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 192,924 KB
最終ジャッジ日時 2025-02-10 22:11:30
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

const ll MOD=998244353;
const ll INF=998244353000000000;
 
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  ll h,w,k;
  cin>>h>>w>>k;
  
  auto f=[&](ll x,ll y)->ll{
    ll tmp=x+1;
    tmp=(tmp+x*(x+1)%MOD);
    if(x>y) tmp=(tmp-(x-y)*(x-y+1)/2+INF)%MOD;
    if(w-y-1<x) tmp=(tmp-(x-w+y+1)*(x-w+y+2)/2+INF)%MOD;
    tmp%=MOD;
    return tmp;
  };
  
  ll ans=0;
  rep(i,k){
    ll x,y,v;
    cin>>x>>y>>v;
    x--,y--;
    ans=(ans+v*f(x,y))%MOD;
  }
  cout<<ans<<endl;
    
  return 0;
}
0