結果
| 問題 |
No.1516 simple 門松列 problem Re:MASTER
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2021-05-21 21:56:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,385 ms / 6,000 ms |
| コード長 | 3,793 bytes |
| コンパイル時間 | 968 ms |
| コンパイル使用メモリ | 82,080 KB |
| 最終ジャッジ日時 | 2025-01-21 14:59:40 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <memory>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
template<ull M>
struct static_modint {
ull x;
static_modint(ull val = 0) : x(val) {}
template<class intTy, enable_if_t<is_integral<intTy>::value&& is_unsigned<intTy>::value, void*> isUnsignedInt = nullptr>
static static_modint mod_construct(intTy val) { return static_modint(val % M); }
template<class intTy, enable_if_t<is_integral<intTy>::value&& is_signed<intTy>::value, void*> isSignedInt = nullptr>
static static_modint mod_construct(intTy val) { ll buf = val % (ll)M; if (buf < 0) buf += M; return static_modint((ull)buf); }
static_modint operator-() const { if (x == 0) return 0; else return M - x; }
static_modint& operator+=(static_modint r) { x += r.x; if (x >= M) x -= M; return *this; }
static_modint operator+(static_modint r) const { static_modint res = x; return res += r; }
static_modint& operator-=(static_modint r) { x += M - r.x; if (x >= M) x -= M; return *this; }
static_modint operator-(static_modint r) const { static_modint res = x; return res -= r; }
static_modint& operator*=(static_modint r) { x = x * r.x % M; return *this; }
static_modint operator*(static_modint r) const { return static_modint(x * r.x % M); }
static_modint pow(ull r) const {
if (r == 0) return static_modint(1);
static_modint res = pow(r / 2);
res *= res;
if (r % 2) res *= *this;
return res;
}
static_modint inv() const { return pow(M - 2); }
static_modint& operator/=(static_modint r) { *this *= r.inv(); return *this; }
static_modint operator/(static_modint r) const { return *this * r.inv(); }
ull& operator*() { return x; }
const ull& operator*() const { return x; }
bool operator==(static_modint r) const { return x == *r; }
bool operator!=(static_modint r) const { return x != *r; }
};
template<class Elem, size_t matrix_sz>
struct static_matrix {
vector<vector<Elem>> X = vector<vector<Elem>>(matrix_sz,vector<Elem>(matrix_sz));
static static_matrix id() { static_matrix res; rep(i, matrix_sz) res[i][i] = 1; return res; }
vector<Elem>& operator[](int x) { return X[x]; }
const vector<Elem>& operator[](int x) const { return X[x]; }
static_matrix operator+(const static_matrix& r) const {
static_matrix res;
rep(i, matrix_sz) rep(j, matrix_sz)
res[i][j] = X[i][j] + r[i][j];
return res;
}
static_matrix operator-(const static_matrix& r) const {
static_matrix res;
rep(i, matrix_sz) rep(j, matrix_sz)
res[i][j] = X[i][j] - r[i][j];
return res;
}
static_matrix operator*(const static_matrix& r) const {
static_matrix res;
rep(i, matrix_sz) rep(j, matrix_sz) rep(k, matrix_sz)
res[i][j] += X[i][k] * r[k][j];
return res;
}
static_matrix pow(ull N) const {
if (N == 0) return id();
static_matrix res = pow(N / 2);
res = res * res;
if (N % 2 == 1) res = res * *this;
return move(res);
}
};
using mll = static_modint<998244353>;
using Mat = static_matrix<mll,204>;
int N,K;
Mat G;
int main(){
cin >> N >> K;
rep(a,K) G[200][(a*10+a)*2] += 1;
rep(a,K) G[200][(a*10+a)*2+1] += a;
rep(a,K) rep(b,K) rep(c,K){
if(a > b) if(b >= c || a == c) continue;
if(a < b) if(b <= c || a == c) continue;
if(a == b) if(b == c) continue;
G[(a*10+b)*2][(b*10+c)*2] += 1;
G[(a*10+b)*2+1][(b*10+c)*2+1] += 1;
G[(a*10+b)*2][(b*10+c)*2+1] += c;
}
rep(i,100) G[i*2][201] += 1;
rep(i,100) G[i*2+1][202] += 1;
auto P = G.pow(N+1);
cout << *(P[200][201]) << " ";
cout << *(P[200][202]) << "\n";
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia