結果

問題 No.1513 simple 門松列 problem
ユーザー 👑 NachiaNachia
提出日時 2021-05-21 21:56:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 3,793 bytes
コンパイル時間 832 ms
コンパイル使用メモリ 86,360 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-10 08:33:11
合計ジャッジ時間 5,479 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
6,820 KB
testcase_01 AC 163 ms
6,820 KB
testcase_02 RE -
testcase_03 AC 323 ms
6,816 KB
testcase_04 AC 295 ms
6,820 KB
testcase_05 AC 297 ms
6,816 KB
testcase_06 AC 296 ms
6,820 KB
testcase_07 AC 189 ms
6,816 KB
testcase_08 AC 323 ms
6,816 KB
testcase_09 AC 136 ms
6,820 KB
testcase_10 AC 136 ms
6,816 KB
testcase_11 AC 136 ms
6,816 KB
testcase_12 AC 163 ms
6,816 KB
testcase_13 AC 189 ms
6,820 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;

0