結果
| 問題 |
No.3044 よくあるカエルさん
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-02-28 23:00:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 91 ms / 2,000 ms |
| コード長 | 3,007 bytes |
| コンパイル時間 | 1,997 ms |
| コンパイル使用メモリ | 202,180 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2025-02-28 23:00:36 |
| 合計ジャッジ時間 | 3,980 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 20 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}
template <class T>
struct Matrix {
vector<vector<T>> A;
Matrix(int n, int m) : A(n, vector<T>(m, 0)) {}
Matrix(int n) : A(n, vector<T>(n, 0)) {}
int height() const {
return (A.size());
}
int width() const {
return (A[0].size());
}
const vector<T> &operator[](int k) const {
return (A[k]);
}
vector<T> &operator[](int k) {
return (A[k]);
}
static Matrix I(int n) {
Matrix mat(n);
for (int i = 0; i < n; i++) mat[i][i] = 1;
return mat;
}
Matrix &operator+=(const Matrix &B) {
int n = height(), m = width();
assert(n == B.height() && m == B.width());
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
(*this)[i][j] += B[i][j];
}
}
return (*this);
}
Matrix &operator-=(const Matrix &B) {
int n = height(), m = width();
assert(n == B.height() && m == B.width());
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
(*this)[i][j] -= B[i][j];
}
}
return (*this);
}
Matrix &operator*=(const Matrix &B) {
int n = height(), m = B.width(), p = width();
assert(p == B.height());
vector<vector<T>> C(n, vector<T>(m, 0));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
for (int k = 0; k < p; k++) {
C[i][j] += (*this)[i][k] * B[k][j];
}
}
}
A.swap(C);
return (*this);
}
Matrix &operator^=(long long k) {
int n = height();
assert(n == width());
Matrix B = Matrix::I(n);
while (k > 0) {
if (k & 1) B *= *this;
*this *= *this;
k >>= 1LL;
}
A.swap(B.A);
return (*this);
}
Matrix operator+(const Matrix &B) const {
return (Matrix(*this) += B);
}
Matrix operator-(const Matrix &B) const {
return (Matrix(*this) -= B);
}
Matrix operator*(const Matrix &B) const {
return (Matrix(*this) *= B);
}
Matrix operator^(const long long k) const {
return (Matrix(*this) ^= k);
}
};
#include<atcoder/modint>
using mint=atcoder::modint998244353;
void Solve(){
int N,T,K,L;
cin>>N>>T>>K>>L;
Matrix<mint>M(T);
M[0][0]=(K-1)/(mint)6;
M[0][1]=(L-K)/(mint)6;
M[0][T-1]=(7-L)/(mint)6;
for(int i=1;i<T;i++){
M[i][i-1]=1;
}
M^=N-1;
mint ans=M[0][0];
cout<<ans.val()<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
Solve();
}