結果

問題 No.2396 等差二項展開
ユーザー SSRSSSRS
提出日時 2023-07-28 21:44:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,382 ms / 6,000 ms
コード長 872 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 167,816 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 05:35:53
合計ジャッジ時間 13,365 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 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 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 12 ms
5,376 KB
testcase_16 AC 173 ms
5,376 KB
testcase_17 AC 722 ms
5,376 KB
testcase_18 AC 1,162 ms
5,376 KB
testcase_19 AC 1,382 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 602 ms
5,376 KB
testcase_24 AC 948 ms
5,376 KB
testcase_25 AC 1,145 ms
5,376 KB
testcase_26 AC 842 ms
5,376 KB
testcase_27 AC 944 ms
5,376 KB
testcase_28 AC 1,036 ms
5,376 KB
testcase_29 AC 949 ms
5,376 KB
testcase_30 AC 684 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N, M;
  int L, K;
  long long B;
  cin >> N >> M >> L >> K >> B;
  M %= B;
  auto convolution = [&](vector<long long> a, vector<long long> b){
    vector<long long> c(L, 0);
    for (int i = 0; i < L; i++){
      for (int j = 0; j < L; j++){
        if (i + j < L){
          c[i + j] += a[i] * b[j];
          c[i + j] %= B;
        } else {
          c[i + j - L] += a[i] * b[j] % B * M;
          c[i + j - L] %= B;
        }
      }
    }
    return c;
  };
  vector<long long> f(L, 0);
  f[0] += 1;
  f[0] %= B;
  if (L == 1){
    f[0] += M;
    f[0] %= B;
  } else {
    f[1] += 1;
    f[1] %= B;
  }
  vector<long long> g(L, 0);
  g[0] = 1;
  g[0] %= B;
  while (N > 0){
    if (N % 2 == 1){
      g = convolution(g, f);
    }
    f = convolution(f, f);
    N /= 2;
  }
  cout << g[K] << endl;
}
0