結果

問題 No.2396 等差二項展開
ユーザー かつっぱ競プロかつっぱ競プロ
提出日時 2023-07-28 22:14:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,399 bytes
コンパイル時間 995 ms
コンパイル使用メモリ 97,768 KB
実行使用メモリ 103,144 KB
最終ジャッジ日時 2024-04-16 06:13:20
合計ジャッジ時間 10,162 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
16,896 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 WA -
testcase_13 AC 10 ms
5,376 KB
testcase_14 AC 16 ms
5,376 KB
testcase_15 AC 1,319 ms
6,912 KB
testcase_16 TLE -
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 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

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