結果

問題 No.2944 Sigma Partition Problem
ユーザー GOTKAKO
提出日時 2024-10-18 22:37:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 611 ms / 4,000 ms
コード長 2,633 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 201,108 KB
最終ジャッジ日時 2025-02-24 21:00:11
ジャッジサーバーID
(参考情報)
judge3 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

long long mod = 998244353;
//入力が必ず-mod<a<modの時.
struct mint{
    long long v = 0;
    mint(){} mint(int a){v = a<0?a+mod:a;} mint(long long a){v = a<0?a+mod:a;}
    mint(unsigned long long a){v = a;}
    long long val(){return v;}
    void modu(){v %= mod;}
 
    mint repeat2mint(const long long a,long long b){
        mint ret = 1,p = a;
        while(b){
            if(b&1) ret *= p;
            p *= p; b >>= 1;
        }
        return ret;
    };
 
    mint &operator=(const mint &b) = default;
    mint operator-() const {return mint(0)-(*this);}
    mint operator+(const mint b){return mint(v)+=b;}
    mint operator-(const mint b){return mint(v)-=b;}
    mint operator*(const mint b){return mint(v)*=b;}
    mint operator/(const mint b){return mint(v)/=b;}
 
    mint operator+=(const mint b){
        v += b.v; if(v >= mod) v -= mod;
        return *this;
    }
    mint operator-=(const mint b){
        v -= b.v; if(v < 0) v += mod; 
        return *this;
    }   
    mint operator*=(const mint b){v = v*b.v%mod; return *this;}
    mint operator/=(mint b){
        if(b == 0) assert(false);
        int left = mod-2;
        while(left){if(left&1) *this *= b; b *= b; left >>= 1;}
        return *this;
    }
 
    mint operator++(int){*this += 1; return *this;}
    mint operator--(int){*this -= 1; return *this;}
    bool operator==(const mint b){return v == b.v;}
    bool operator!=(const mint b){return v != b.v;}
    bool operator>(const mint b){return v > b.v;}
    bool operator>=(const mint b){return v >= b.v;}
    bool operator<(const mint b){return v < b.v;}
    bool operator<=(const mint b){return v <= b.v;}
 
    mint pow(const long long x){return repeat2mint(v,x);}
    mint inv(){return mint(1)/v;}
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int N = 4000;
    vector M(N+1,vector<mint>(N+1)),L = M;
    M.at(0).at(0) = 1; L.at(0).at(0) = 1;
    for(int i=1; i<=N; i++) M.at(0).at(i) = 1;

    for(int i=1; i<=N; i++){
        for(int k=1; k<=i; k++) M.at(i).at(k) += M.at(i-k).at(k);
        for(int k=1; k<=N; k++) M.at(i).at(k) += M.at(i).at(k-1);    
    }
    for(int i=1; i<=N; i++){
        for(int k=1; k<=i; k++){
            L.at(i).at(k) += L.at(i-1).at(k-1);
            L.at(i).at(k) += L.at(i-k).at(k);
        }
    }
    for(int i=0; i<=N; i++) for(int k=1; k<=N; k++) L.at(i).at(k) += L.at(i).at(k-1);

    int Q; cin >> Q;
    while(Q--){
        int t,n,k; cin >> t >> n >> k;
        if(t == 1) cout << M.at(n).at(k).v << "\n";
        else cout << L.at(n).at(k).v << "\n";
    }
}
0