結果

問題 No.2857 Div Array
ユーザー GOTKAKOGOTKAKO
提出日時 2024-08-25 14:18:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 3,094 bytes
コンパイル時間 2,106 ms
コンパイル使用メモリ 209,980 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-08-25 14:18:31
合計ジャッジ時間 4,005 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 5 ms
6,944 KB
testcase_11 AC 89 ms
6,944 KB
testcase_12 AC 21 ms
6,940 KB
testcase_13 AC 9 ms
6,944 KB
testcase_14 AC 88 ms
6,940 KB
testcase_15 AC 10 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 82 ms
6,940 KB
testcase_18 AC 65 ms
6,940 KB
testcase_19 AC 38 ms
6,940 KB
testcase_20 AC 104 ms
6,940 KB
testcase_21 AC 106 ms
6,940 KB
testcase_22 AC 104 ms
6,944 KB
testcase_23 AC 106 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,944 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,948 KB
testcase_29 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

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;}
};

vector<vector<mint>> multima(vector<vector<mint>> &A,vector<vector<mint>> &B){
    int siza = A.size(),sizb = B.at(0).size();
    vector<vector<mint>> ret(siza,vector<mint>(sizb));
    for(int i=0; i<siza; i++) for(int k=0; k<sizb; k++){
        for(int l=0; l<A.at(i).size(); l++){
            ret.at(i).at(k) += A.at(i).at(l)*B.at(l).at(k);
            //ret.at(i).at(k) %= mod;
        }
    }
    return ret;
    //計算できる行列のみ.
}

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

    int N,M,K; cin >> N >> M >> K;
    vector<int> ap(M+1),all;
    for(int i=1; i<=M; i++){
        int a = M/i;
        ap.at(a)++;
        if(ap.at(a) == 1) all.push_back(a);
    }

    int n = all.size();
    vector<vector<mint>> Z(n,vector<mint>(n)),A(n,vector<mint>(1));
    for(int i=0; i<n; i++){
        int a = all.at(i);
        A.at(i).at(0) = ap.at(a);
    }
    for(int i=0; i<n; i++){
        int a = all.at(i);
        for(int k=0; k<n; k++){
            int b = all.at(k);
            if(abs(a-b) > K) continue;
            Z.at(k).at(i) = ap.at(b);
        }
    }

    N--;
    while(N){
        if(N&1) A = multima(Z,A);
        Z = multima(Z,Z); N>>=1;
    }
    mint answer = 0;
    for(auto &h : A) answer += h.at(0);
    cout << answer.v << endl;
}
0