結果

問題 No.1516 simple 門松列 problem Re:MASTER
ユーザー 👑 NachiaNachia
提出日時 2021-05-21 21:56:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,348 ms / 6,000 ms
コード長 3,793 bytes
コンパイル時間 920 ms
コンパイル使用メモリ 86,828 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-10 08:32:24
合計ジャッジ時間 14,091 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
6,820 KB
testcase_01 AC 164 ms
6,820 KB
testcase_02 AC 675 ms
6,816 KB
testcase_03 AC 325 ms
6,816 KB
testcase_04 AC 299 ms
6,820 KB
testcase_05 AC 298 ms
6,816 KB
testcase_06 AC 297 ms
6,816 KB
testcase_07 AC 190 ms
6,820 KB
testcase_08 AC 327 ms
6,816 KB
testcase_09 AC 137 ms
6,820 KB
testcase_10 AC 136 ms
6,816 KB
testcase_11 AC 138 ms
6,816 KB
testcase_12 AC 164 ms
6,820 KB
testcase_13 AC 191 ms
6,816 KB
testcase_14 AC 1,181 ms
6,820 KB
testcase_15 AC 1,158 ms
6,820 KB
testcase_16 AC 1,348 ms
6,820 KB
testcase_17 AC 1,130 ms
6,820 KB
testcase_18 AC 858 ms
6,816 KB
testcase_19 AC 1,099 ms
6,820 KB
testcase_20 AC 859 ms
6,816 KB
testcase_21 AC 857 ms
6,820 KB
権限があれば一括ダウンロードができます

ソースコード

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