結果
問題 |
No.2396 等差二項展開
|
ユーザー |
|
提出日時 | 2023-07-28 22:12:26 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,386 bytes |
コンパイル時間 | 943 ms |
コンパイル使用メモリ | 97,776 KB |
実行使用メモリ | 10,496 KB |
最終ジャッジ日時 | 2024-10-06 19:11:12 |
合計ジャッジ時間 | 9,467 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 9 WA * 7 TLE * 1 -- * 14 |
ソースコード
#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; 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; } mat = matPow(mat, N); cout << mat[K][0] << endl; return 0; }