結果

問題 No.2685 Cell Proliferation (Easy)
ユーザー 👑 binapbinap
提出日時 2024-03-20 23:41:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 12,548 bytes
コンパイル時間 5,145 ms
コンパイル使用メモリ 283,104 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-09-30 09:38:36
合計ジャッジ時間 6,072 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 4 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 3 ms
5,248 KB
testcase_04 AC 3 ms
5,248 KB
testcase_05 AC 3 ms
5,248 KB
testcase_06 AC 2 ms
5,248 KB
testcase_07 AC 3 ms
5,248 KB
testcase_08 AC 3 ms
5,248 KB
testcase_09 AC 3 ms
5,248 KB
testcase_10 AC 3 ms
5,248 KB
testcase_11 AC 3 ms
5,248 KB
testcase_12 AC 3 ms
5,248 KB
testcase_13 AC 3 ms
5,248 KB
testcase_14 AC 4 ms
5,248 KB
testcase_15 AC 3 ms
5,248 KB
testcase_16 AC 3 ms
5,248 KB
testcase_17 AC 2 ms
5,248 KB
testcase_18 AC 3 ms
5,248 KB
testcase_19 AC 3 ms
5,248 KB
testcase_20 AC 2 ms
5,248 KB
testcase_21 AC 2 ms
5,248 KB
testcase_22 AC 3 ms
5,248 KB
testcase_23 AC 3 ms
5,248 KB
testcase_24 AC 4 ms
5,248 KB
testcase_25 AC 3 ms
5,248 KB
testcase_26 AC 3 ms
5,248 KB
testcase_27 AC 2 ms
5,248 KB
testcase_28 AC 4 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long>> vvl;
typedef long double ld;
typedef pair<int, int> P;

ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const static_modint<m>& a) {os << a.val(); return os;}
template <int m> ostream& operator<<(ostream& os, const dynamic_modint<m>& a) {os << a.val(); return os;}
template<typename T> istream& operator>>(istream& is, vector<T>& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;}
template<typename U, typename T> ostream& operator<<(ostream& os, const pair<U, T>& p){os << p.first << ' ' << p.second; return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;}

template<typename T> void chmin(T& a, T b){a = min(a, b);}
template<typename T> void chmax(T& a, T b){a = max(a, b);}

using mint = modint998244353;

// combination mod prime
// https://youtu.be/8uowVvQ_-Mo?t=6002
// https://youtu.be/Tgd_zLfRZOQ?t=9928
struct modinv {
  int n; vector<mint> d;
  modinv(): n(2), d({0,1}) {}
  mint operator()(int i) {
    while (n <= i) d.push_back(-d[mint::mod()%n]*(mint::mod()/n)), ++n;
    return d[i];
  }
  mint operator[](int i) const { return d[i];}
} invs;
struct modfact {
  int n; vector<mint> d;
  modfact(): n(2), d({1,1}) {}
  mint operator()(int i) {
    while (n <= i) d.push_back(d.back()*n), ++n;
    return d[i];
  }
  mint operator[](int i) const { return d[i];}
} facts;
struct modfactinv {
  int n; vector<mint> d;
  modfactinv(): n(2), d({1,1}) {}
  mint operator()(int i) {
    while (n <= i) d.push_back(d.back()*invs(n)), ++n;
    return d[i];
  }
  mint operator[](int i) const { return d[i];}
} ifacts;
mint comb(int n, int k) {
  if (n < k || k < 0) return 0;
  return facts(n)*ifacts(k)*ifacts(n-k);
}

template< typename T >
struct FormalPowerSeries : vector< T > {
  using vector< T >::vector;
  using P = FormalPowerSeries;
  
  template<class...Args> FormalPowerSeries(Args...args): vector<T>(args...) {}
  FormalPowerSeries(initializer_list<T> a): vector<T>(a.begin(),a.end()) {}

  using MULT = function< P(P, P) >;

  static MULT &get_mult() {
    static MULT mult = [&](P a, P b){
		P res(convolution(a, b));
		return res;
	};
    return mult;
  }

  static void set_fft(MULT f) {
    get_mult() = f;
  }

  void shrink() {
    while(this->size() && this->back() == T(0)) this->pop_back();
  }

  P operator+(const P &r) const { return P(*this) += r; }

  P operator+(const T &v) const { return P(*this) += v; }

  P operator-(const P &r) const { return P(*this) -= r; }

  P operator-(const T &v) const { return P(*this) -= v; }

  P operator*(const P &r) const { return P(*this) *= r; }

  P operator*(const T &v) const { return P(*this) *= v; }

  P operator/(const P &r) const { return P(*this) /= r; }

  P operator%(const P &r) const { return P(*this) %= r; }

  P &operator+=(const P &r) {
    if(r.size() > this->size()) this->resize(r.size());
    for(int i = 0; i < int(r.size()); i++) (*this)[i] += r[i];
    return *this;
  }

  P &operator+=(const T &r) {
    if(this->empty()) this->resize(1);
    (*this)[0] += r;
    return *this;
  }

  P &operator-=(const P &r) {
    if(r.size() > this->size()) this->resize(r.size());
    for(int i = 0; i < int(r.size()); i++) (*this)[i] -= r[i];
    shrink();
    return *this;
  }

  P &operator-=(const T &r) {
    if(this->empty()) this->resize(1);
    (*this)[0] -= r;
    shrink();
    return *this;
  }

  P &operator*=(const T &v) {
    const int n = (int) this->size();
    for(int k = 0; k < n; k++) (*this)[k] *= v;
    return *this;
  }

  P &operator*=(const P &r) {
    if(this->empty() || r.empty()) {
      this->clear();
      return *this;
    }
    assert(get_mult() != nullptr);
    return *this = get_mult()(*this, r);
  }

  P &operator%=(const P &r) {
    return *this -= *this / r * r;
  }

  P operator-() const {
    P ret(this->size());
    for(int i = 0; i < int(this->size()); i++) ret[i] = -(*this)[i];
    return ret;
  }

  P &operator/=(const P &r) {
    if(this->size() < r.size()) {
      this->clear();
      return *this;
    }
    int n = this->size() - r.size() + 1;
    return *this = (rev().pre(n) * r.rev().inv(n)).pre(n).rev(n);
  }

  P pre(int sz) const {
    return P(begin(*this), begin(*this) + min((int) this->size(), sz));
  }

  P operator>>(int sz) const {
    if((int)this->size() <= sz) return {};
    P ret(*this);
    ret.erase(ret.begin(), ret.begin() + sz);
    return ret;
  }

  P operator<<(int sz) const {
    P ret(*this);
    ret.insert(ret.begin(), sz, T(0));
    return ret;
  }

  P rev(int deg = -1) const {
    P ret(*this);
    if(deg != -1) ret.resize(deg, T(0));
    reverse(begin(ret), end(ret));
    return ret;
  }

  P diff() const {
    const int n = (int) this->size();
    P ret(max(0, n - 1));
    for(int i = 1; i < n; i++) ret[i - 1] = (*this)[i] * T(i);
    return ret;
  }

  P integral() const {
    const int n = (int) this->size();
    P ret(n + 1);
    ret[0] = T(0);
    for(int i = 0; i < n; i++) ret[i + 1] = (*this)[i] / T(i + 1);
    return ret;
  }

  // F(0) must not be 0
  P inv(int deg = -1) const {
    assert(((*this)[0]) != T(0));
    const int n = (int) this->size();
    if(deg == -1) deg = n;
    P ret({T(1) / (*this)[0]});
    for(int i = 1; i < deg; i <<= 1) {
      ret = (ret + ret - ret * ret * pre(i << 1)).pre(i << 1);
    }
    return ret.pre(deg);
  }

  // F(0) must be 1
  P log(int deg = -1) const {
    assert((*this)[0] == 1);
    const int n = (int) this->size();
    if(deg == -1) deg = n;
    return (this->diff() * this->inv(deg)).pre(deg - 1).integral();
  }

  P sqrt(int deg = -1) const {
    const int n = (int) this->size();
    if(deg == -1) deg = n;

    if((*this)[0] == T(0)) {
      for(int i = 1; i < n; i++) {
        if((*this)[i] != T(0)) {
          if(i & 1) return {};
          if(deg - i / 2 <= 0) break;
          auto ret = (*this >> i).sqrt(deg - i / 2) << (i / 2);
          if(int(ret.size()) < deg) ret.resize(deg, T(0));
          return ret;
        }
      }
      return P(deg, 0);
    }

    P ret({T(1)});
    T inv2 = T(1) / T(2);
    for(int i = 1; i < deg; i <<= 1) {
      ret = (ret + pre(i << 1) * ret.inv(i << 1)) * inv2;
    }
    return ret.pre(deg);
  }

  // F(0) must be 0
  P exp(int deg = -1) const {
    assert((*this)[0] == T(0));
    const int n = (int) this->size();
    if(deg == -1) deg = n;
    P ret({T(1)});
    for(int i = 1; i < deg; i <<= 1) {
      ret = (ret * (pre(i << 1) + T(1) - ret.log(i << 1))).pre(i << 1);
    }
    return ret.pre(deg);
  }

  P pow(int k, int deg = -1) const {
    const int n = (int) this->size();
    if(deg == -1) deg = n;
    for(int i = 0; i < n; i++) {
      if((*this)[i] != T(0)) {
        T rev = T(1) / (*this)[i];
        P C(*this * rev);
        P D(n - i);
        for(int j = i; j < n; j++) D[j - i] = C[j];
        D = (D.log() * T(k)).exp() * (*this)[i].pow(k);
        P E(deg);
        if(i * k > deg) return E;
        auto S = i * k;
        for(int j = 0; j + S < deg && j < D.size(); j++) E[j + S] = D[j];
        return E;
      }
    }
    return *this;
  }
  
	P taylor_shift(T x) const {
		const int n = (int) this->size();
		P p(n), q(n);
		for(int i = 0; i < n; i++) p[i] = facts(i) * (*this)[i];
		for(int i = 0; i < n; i++) q[i] = ifacts(n - 1 - i) * x.pow(n - 1 - i);
		p *= q;
		p = p >> (n - 1);
		for(int i = 0; i < n; i++) p[i] *= ifacts(i);
		return p;
	}

  T get(int idx){
  	assert(idx >= 0);
  	if(idx < int(this->size())) return (*this)[idx];
  	else return T(0);
  }
  
  void set(int idx, T x){
  	assert(idx >= 0);
  	if(idx < int(this->size())) (*this)[idx] = x;
  	else{
  		this->resize(idx + 1);
  		T(0);
  	}
  	return;
  }

  T eval(T x) const {
    T r = 0, w = 1;
    for(auto &v : *this) {
      r += w * v;
      w *= x;
    }
    return r;
  }
};

template<typename T>
T Bostan_Mori(FormalPowerSeries<T> P, FormalPowerSeries<T> Q, ll n){
	assert(P.size() == Q.size());
	if(n == 0) return P[0] / Q[0];
	const int k = P.size();
	FormalPowerSeries<T> R = Q;
	rep(i, k) if(i % 2 == 1) R[i] *= (T)-1;
	P *= R;
	Q *= R;
	FormalPowerSeries<T> U(k), V(k);
	if(n % 2 == 1) rep(i, k - 1) U[i] = P[2 * i + 1];
	else rep(i, k) U[i] = P[2 * i];
	rep(i, k) V[i] = Q[2 * i];
	return Bostan_Mori(U, V, n / 2);
}

// C = A * B in the full_relaxed way
// c_i = \sigma_{j = 0}^{i} a_{j} b_{i - j}
// Postulate: at the point of i, all of the a_j, b_j (0 <= j <= i) are known
// O(N(longN)^2)
// 5e5 * 5e5 -> 3300 ms
// https://judge.yosupo.jp/submission/167521
template<typename T>
void convolution_online(FormalPowerSeries<T>& a, FormalPowerSeries<T>& b, FormalPowerSeries<T>& c, int idx){
	assert(int(c.size()) >= int(a.size()) + int(b.size()) - 1);
	int two = 1;
	rep(_, 30){
		if(idx == 0 and two >= 2) break;
		if(!(idx % two == max(0, two - 2))) break;
		{
			FormalPowerSeries<T> a1(two), b1(two), c1;
			rep(i, two){a1[i] = a[(two - 1) + i]; b1[i] = b[idx - (two - 1) + i];}
			c1 = a1 * b1;
			rep(i, two * 2 - 1) c[idx + i] += c1[i];
		}
		if(idx == (two - 1) * 2) break;
		{
			FormalPowerSeries<T> a2(two), b2(two), c2;
			rep(i, two){a2[i] = a[idx - (two - 1) + i]; b2[i] = b[(two - 1) + i];}
			c2 = a2 * b2;
			rep(i, two * 2 - 1) c[idx + i] += c2[i];
		}
		two *= 2;
	}
}

namespace sparse{
	// f^k (mod x^n)for sparse FPS f
	// O(N * M) (M is for # of terms of f)
	// Requirement : f0 = 1
	vector<mint> pow(vector<pair<int, mint>> f, int N, mint k){
		assert(int(f.size()) > 0);
		assert(f[0].first == 0);
		assert(f[0].second == (mint)1);
		vector<pair<int, mint>> f_prime;
		for(auto [n, c] : f) if(n > 0) f_prime.emplace_back(n - 1, c * n);
		vector<mint> F(N);
		vector<mint> F_prime(N);
		F[0] = 1;
		rep(n, N - 1){
			mint res = 0;
			for(auto [m, c] : f){
				if(m == 0) continue;
				if(m > n) break;
				res -= c * F_prime[n - m];
			}
			for(auto [m, c] : f_prime){
				if(m > n) break;
				res += k * c * F[n - m];
			}
			F_prime[n] = res;
			F[n + 1] = res / (n + 1);
		}
		return F;
	}
	// exp(f) (mod x^n)for sparse FPS f
	// O(N * M) (M is for # of terms of f)
	// Requirement : f0 = 0
	vector<mint> exp(vector<pair<int, mint>> f, int N){
		assert(int(f.size()) > 0);
		assert(f[0].first > 0 or f[0].second == 0);
		vector<pair<int, mint>> f_prime;
		for(auto [n, c] : f) if(n > 0) f_prime.emplace_back(n - 1, c * n);
		vector<mint> F(N);
		vector<mint> F_prime(N);
		F[0] = 1;
		rep(n, N - 1){
			mint res = 0;
			for(auto [m, c] : f_prime){
				if(m > n) break;
				res += c * F[n - m];
			}
			F_prime[n] = res;
			F[n + 1] = res / (n + 1);
		}
		return F;
	}
	// g / f (mod x^n for sparse FPS f and not sparse FPS g
	// O(N * M) (M is for # of terms of f)
	// Requirement : f0 = 1
	vector<mint> quotient(vector<mint> g, vector<pair<int, mint>> f, int N){
		assert(int(g.size()) == N);
		assert(int(f.size()) > 0);
		assert(f[0].first == 0);
		assert(f[0].second == (mint)1);
		vector<mint> F(N);
		F[0] = g[0];
		for(int n = 1; n < N; n++){
			mint res = g[n];
			for(auto [m, c] : f){
				if(m == 0) continue;
				if(m > n) break;
				res -= c * F[n - m];
			}
			F[n] = res;
		}
		return F;
	}
	// log f (mod x^n) for sparse FPS f
	// O(N * M) (M is for # of terms of f)
	// Requirement : f0 = 1
	vector<mint> log(vector<pair<int, mint>> f, int N){
		assert(int(f.size()) > 0);
		assert(f[0].first == 0);
		assert(f[0].second == (mint)1);
		vector<mint> f_prime(N);
		for(auto [n, c] : f){
			if(n == 0) continue;
			f_prime[n - 1] = c * n;
		}
		vector<mint> F_prime = quotient(f_prime, f, N);
		vector<mint> F(N);
		rep(n, N - 1) F[n + 1] = F_prime[n] / (n + 1);
		return F;
	}
}

int main(){
	int p1, p2, q1, q2, t;
	cin >> p1 >> p2 >> q1 >> q2 >> t;
	mint p = (mint)(p1)/ p2;
	mint q = (mint)(q1)/ q2;
	FormalPowerSeries<mint> f(t + 1);
	FormalPowerSeries<mint> g(t + 1);
	FormalPowerSeries<mint> h(2 * t + 5);
	rep(i, t + 1){
		g[i] = q.pow((long long)i * (i + 1) / 2);
	}
	f[0] = 1;
	rep(i, t){
		convolution_online(f, g, h, i);
		f[i + 1] = p * h[i] + g[i + 1];
	}
//	cout << f;
//	cout << g;
	cout << f[t] << "\n";
	return 0;
}
0