結果

問題 No.2857 Div Array
ユーザー HIcoderHIcoder
提出日時 2024-09-03 21:23:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,758 bytes
コンパイル時間 1,720 ms
コンパイル使用メモリ 124,424 KB
実行使用メモリ 48,544 KB
最終ジャッジ日時 2024-09-03 21:24:00
合計ジャッジ時間 5,592 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
6,816 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cassert>
#include<random>
#include<set>
#include<map>
#include<cassert>
#include<unordered_map>
#include<bitset>
#include<numeric>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=1<<30;
const ll INF=1LL<<62;
typedef pair<int,ll> P;
typedef pair<int,P> PP; 
const ll MOD=998244353;
const int dy[]={0,1,0,-1};
const int dx[]={1,0,-1,0};


const int mod = 998244353;
struct mint {
  long long x; // typedef long long long long;
  mint(long long x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}//後ろのconstはメンバxを変更しないことを示す
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  bool operator==(const mint a) const {return a.x==x;}
  mint pow(unsigned long long int t) const {
    assert(t>=0);
    if (!t) return 1;
    //aがtで割り切れない場合には t%=(mod-1)をして良い
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};

std::istream& operator>>(std::istream& is, mint& a) { return is >> a.x;}
std::ostream& operator<<(std::ostream& os, const mint& a) { return os << a.x;}



struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


vector<vector<mint>> mat(vector<vector<mint>> A,vector<vector<mint>> B,int N){
    //A*B
    vector<vector<mint> > C(N,vector<mint>(N));
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            mint ans=0;
            for(int k=0;k<N;k++){
                ans = (ans + A[i][k]*B[k][j]);
            }
            C[i][j] = ans;
        }
    }
    return C;

}


//行列xのy乗
vector<vector<mint>> multi_matrix(vector<vector<mint>>x, ll y ,int N){

    vector<vector<mint>> pow(N,vector<mint>(N));
    for(int i=0;i<N;i++) pow[i][i]=1;//単位行列
    
    while(y>0){
        if(y&1){
            pow = mat(pow,x,N);
        }
        y = y>>1;
        x = mat(x,x,N);
    }

    return pow;
} 


int main(){
    ll N,M,K;
    cin>>N>>M>>K;


    vector<vector<mint>> A(M+1,vector<mint>(M+1));
    for(int x=1;x<=M;x++){
        int c=M/x;
        for(int y=1;y<=M;y++){
            int u=M/y;
            if(1<=u && u<=M && abs(c-u)<=1){
                //xからyへの遷移がある
                A[y][x]+=1;
            }
            
        }
    }

    // for(int x=1;x<=M;x++){
    //     for(int t=1;t<=M;t++){
    //         cout<<"A["<<t<<"]["<<x<<"]="<<A[t][x]<<endl;
    //     }
    // }

    auto res = multi_matrix(A,N-1,M+1);


    vector<mint> dp(M+1,0);
    for(int i=1;i<=M;i++) dp[i]=1;

    // for(int i=0;i<N;i++){
    //     vector<mint> ndp(M+1,0);
    //     swap(dp,ndp);
    // }
    mint ans=0;
    for(int i=1;i<=M;i++){
        for(int j=1;j<=M;j++){
            ans += res[i][j]*dp[j];
        }
    }
    cout<<ans<<endl;

}
0