結果

問題 No.2396 等差二項展開
ユーザー かつっぱ競プロ
提出日時 2023-07-28 22:14:52
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,399 bytes
コンパイル時間 849 ms
コンパイル使用メモリ 98,396 KB
実行使用メモリ 18,344 KB
最終ジャッジ日時 2024-10-06 19:16:56
合計ジャッジ時間 9,685 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 13 WA * 3 TLE * 1 -- * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using Int = long long;
using Real = long double;
using CP = complex<Real>;
using P = pair<Int, Int>;

const Int MOD = 1000000007;
const Int MOD2 = 998244353;
const Int LINF = (1LL << 60);
const int INF = (1000000007);
const Real EPS = 1e-10;
const long double PI = 3.141592653589793238462643383279502884L;

using Matrix = vector<vector<Int>>;

Int mod;

Matrix operator*(Matrix &a, Matrix &b){
  int n = a.size();
  Matrix c(n, vector<Int>(n, 0));
  for(int i = 0;i < n;i++)
    for(int j = 0;j < n;j++)
      for(int k = 0;k < n;k++)
	(c[i][k] += a[i][j] * b[j][k] % mod) %= mod;
  
  return c;
}

Matrix matPow(Matrix &a, Int n){
  if(n == 1)return a;
  Matrix aa = a * a;
  Matrix half = matPow(aa, n / 2);
  if(n % 2 == 0){
    return half;
  }
  else{
    return a * half;
  }
}


int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    Int N, M, L, K, B;
    cin >> N >> M >> L >> K >> B;
    mod = B;
    Matrix mat(L, vector<Int>(L));
    for(int i = 0;i < L;i++){
      mat[i][i] = 1;
      if(i + 1 < L)
	mat[i+1][i] = 1;
      else
	mat[0][i] = M % B;
    }

    mat = matPow(mat, N);
    cout << mat[K][0] << endl;
    
    return 0;
}
0