結果

問題 No.2452 Incline
ユーザー otoshigootoshigo
提出日時 2023-09-01 21:41:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 909 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 77,836 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-01 21:41:39
合計ジャッジ時間 2,017 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 72 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<atcoder/modint>
using namespace std;
using ll=long long;
using mint=atcoder::modint998244353;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

mint f(ll N,ll M,ll X){
    if(X<0)return 0;
    ll d=M%N;
    mint ans=0;
    mint K=M/N,P=(X/N)*(d+1);
    if(X%N<d)P+=X%N+1;
    else P+=d+1;
    ans+=(K+1)*P;
    mint L=K-1,Q=(X/N)*(N-d-1);
    if(X%N>d)Q+=X%N-d-1;
    ans+=(L+1)*Q;
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin>>T;
    while(T--){
        ll N,M,L,R;
        cin>>N>>M>>L>>R;
        N--;
        mint ans=f(N,M,R)-f(N,M,L-1);
        cout<<ans.val()<<"\n";
    }
}
0