結果

問題 No.1516 simple 門松列 problem Re:MASTER
ユーザー 👑 NachiaNachia
提出日時 2021-05-21 21:56:02
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,297 ms / 6,000 ms
コード長 3,793 bytes
コンパイル時間 844 ms
コンパイル使用メモリ 85,992 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-07-31 15:16:06
合計ジャッジ時間 13,510 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
4,376 KB
testcase_01 AC 157 ms
4,376 KB
testcase_02 AC 653 ms
4,380 KB
testcase_03 AC 312 ms
4,380 KB
testcase_04 AC 294 ms
4,376 KB
testcase_05 AC 289 ms
4,384 KB
testcase_06 AC 287 ms
4,380 KB
testcase_07 AC 187 ms
4,380 KB
testcase_08 AC 313 ms
4,376 KB
testcase_09 AC 133 ms
4,376 KB
testcase_10 AC 131 ms
4,380 KB
testcase_11 AC 130 ms
4,380 KB
testcase_12 AC 154 ms
4,376 KB
testcase_13 AC 184 ms
4,380 KB
testcase_14 AC 1,157 ms
4,376 KB
testcase_15 AC 1,121 ms
4,380 KB
testcase_16 AC 1,297 ms
4,380 KB
testcase_17 AC 1,100 ms
4,376 KB
testcase_18 AC 838 ms
4,380 KB
testcase_19 AC 1,083 ms
4,380 KB
testcase_20 AC 837 ms
4,380 KB
testcase_21 AC 827 ms
4,504 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