結果

問題 No.2229 Treasure Searching Rod (Hard)
ユーザー HIcoderHIcoder
提出日時 2023-07-13 17:37:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 1,834 bytes
コンパイル時間 957 ms
コンパイル使用メモリ 111,072 KB
実行使用メモリ 6,336 KB
最終ジャッジ日時 2023-10-13 06:41:03
合計ジャッジ時間 6,195 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 174 ms
6,336 KB
testcase_08 AC 193 ms
6,284 KB
testcase_09 AC 164 ms
6,268 KB
testcase_10 AC 175 ms
6,276 KB
testcase_11 AC 170 ms
6,148 KB
testcase_12 AC 97 ms
4,624 KB
testcase_13 AC 95 ms
4,624 KB
testcase_14 AC 85 ms
4,564 KB
testcase_15 AC 189 ms
6,336 KB
testcase_16 AC 189 ms
6,168 KB
testcase_17 AC 190 ms
6,336 KB
testcase_18 AC 190 ms
6,332 KB
testcase_19 AC 188 ms
6,264 KB
testcase_20 AC 190 ms
6,320 KB
testcase_21 AC 190 ms
6,160 KB
testcase_22 AC 189 ms
6,164 KB
testcase_23 AC 74 ms
4,484 KB
testcase_24 AC 99 ms
4,692 KB
testcase_25 AC 115 ms
5,020 KB
testcase_26 AC 45 ms
4,352 KB
testcase_27 AC 15 ms
4,348 KB
testcase_28 AC 154 ms
5,620 KB
testcase_29 AC 147 ms
5,524 KB
testcase_30 AC 22 ms
4,352 KB
testcase_31 AC 41 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set> 
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include <unordered_set>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=998244353;


ll mod_pow(ll x,ll y,ll mod){

    ll res=1;

    while(y>0){
        if(y&1){
            res*=x;
            res%=mod;
        }
        x*=x;
        x%=mod;
        y/=2;
    }
    return res;
}

int main(){
    int H,W,K;
    cin>>H>>W>>K;
    
    vector<int> x(K),y(K);
    vector<ll> v(K);
    for(int k=0;k<K;k++){
        cin>>x[k]>>y[k]>>v[k];
    }

    ll inv2=mod_pow(2,MOD-2,MOD);

   
    auto cumsum=[&](ll n){
        //1+2+3+...+n
        ll res=n%MOD;
        res*=(n+1)%MOD;

        res%=MOD;
        
        res*=inv2;
        
        res%=MOD;
        return res;
    };

    //[l,r]
    auto cumdif=[&](ll l,ll r){

        ll res=cumsum(r);
        if(l>=1){
            res-=cumsum(l-1);
            res+=MOD;
            res%=MOD;
        }
        return res;

    };

    //タカラが(px,py)にある

    auto f=[&](ll px,ll py){
        ll t=px+py;
        ll u=px-py;
        
        ll lb=max(1LL,1-u);

        ll c1=cumdif(lb,py);//[lb,py]
        c1+=u*(py-lb+1)%MOD;
        c1%=MOD;


        ll ub=min(1LL*W,t-1);
    
        ll len=ub;
        len-=(py-1+MOD)%MOD;
        len+=MOD;
        len%=MOD;

        ll c2=t*len%MOD;


        c2-=cumdif(py,ub);//[py,ub]
        c2+=MOD;
        c2%=MOD;

        ll res=(c1+c2)%MOD;

        res-=(px)%MOD;
        res+=MOD;
        res%=MOD;
        

        return res;
    };
    

    ll ans=0;
    for(int k=0;k<K;k++){
        ans+=v[k]*f(x[k],y[k])%MOD;
        ans%=MOD;
    }

    cout<<ans<<endl;


}
0