Submission #7958349


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
	static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
	ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
	ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
	int get() const { return (int)x; }
	ModInt& operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt& operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt& operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt& operator/=(ModInt that) { return *this *= that.inverse(); }
	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
	ModInt inverse() const {
		long long a = x, b = MOD, u = 1, v = 0;
		while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
		return ModInt(u);
	}
	bool operator==(ModInt that) const { return x == that.x; }
	bool operator!=(ModInt that) const { return x != that.x; }
	ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
	ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r;
}
template<typename T, int FAC_MAX> struct Comb {
	vector<T> fac, ifac;
	Comb() {
		fac.resize(FAC_MAX, 1); ifac.resize(FAC_MAX, 1); rep(i, 1, FAC_MAX)fac[i] = fac[i - 1] * i;
		ifac[FAC_MAX - 1] = T(1) / fac[FAC_MAX - 1]; rrep(i, FAC_MAX - 2, 1)ifac[i] = ifac[i + 1] * T(i + 1);
	}
	T aPb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b]; }
	T aCb(int a, int b) { if (b < 0 || a < b) return T(0); return fac[a] * ifac[a - b] * ifac[b]; }
	// nHk = (n+k-1)Ck : n is separator
	T nHk(int n, int k) {
		if (n == 0 && k == 0) return T(1); if (n <= 0 || k < 0) return 0;
		return aCb(n + k - 1, k);
	} 
	// combination of paris for n
	T pairCombination(int n) { if (n % 2 == 1)return T(0); return fac[n] * ifac[n / 2] / (T(2) ^ (n / 2)); }
	// (0,0) -> (a,b)   constraint: y <= x
	T catalanNumber(int a, int b) {
		return aCb(a + b, a) - aCb(a + b, b - 1);
	}
};
typedef ModInt<998244353> mint;
vector<pair<char, int>> runLengthEncoding(string s) {
	int n = s.length();

	vector<pair<char, int>> res;
	char pre = s[0];
	int cnt = 1;
	rep(i, 1, n) {
		if (pre != s[i]) {
			res.push_back({ pre, cnt });
			pre = s[i];
			cnt = 1;
		}
		else cnt++;
	}

	res.push_back({ pre, cnt });
	return res;
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/











Comb<mint, 201010> com;
int N;
string S;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> S;

	auto rl = runLengthEncoding(S);

	mint ans = 1;
	fore(p, rl) ans *= com.catalanNumber(p.second, p.second);
	cout << ans << endl;
}





Submission Info

Submission Time
Task D - Maximin Game
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 200
Code Size 4435 Byte
Status AC
Exec Time 6 ms
Memory 2684 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 2
AC × 57
Set Name Test Cases
Sample sample_01, sample_02
All large_a_0, large_a_1, large_a_2, large_b0_0, large_b0_1, large_b0_2, large_b1_0, large_b1_1, large_b1_2, large_m_0, large_m_1, large_m_2, large_r_0, large_r_1, large_r_2, large_r_3, large_r_4, large_r_5, large_r_6, large_r_7, large_r_8, large_r_9, large_s0_0, large_s0_1, large_s0_2, large_s1_0, large_s1_1, large_s1_2, sample_01, sample_02, small_0_0, small_1_0, small_a_0, small_a_1, small_a_2, small_b0_0, small_b0_1, small_b0_2, small_b1_0, small_b1_1, small_b1_2, small_r_0, small_r_1, small_r_2, small_r_3, small_r_4, small_r_5, small_r_6, small_r_7, small_r_8, small_r_9, small_s0_0, small_s0_1, small_s0_2, small_s1_0, small_s1_1, small_s1_2
Case Name Status Exec Time Memory
large_a_0 AC 5 ms 2048 KB
large_a_1 AC 5 ms 2304 KB
large_a_2 AC 5 ms 2048 KB
large_b0_0 AC 4 ms 1920 KB
large_b0_1 AC 5 ms 2048 KB
large_b0_2 AC 4 ms 1920 KB
large_b1_0 AC 4 ms 1920 KB
large_b1_1 AC 4 ms 1920 KB
large_b1_2 AC 4 ms 1920 KB
large_m_0 AC 6 ms 2636 KB
large_m_1 AC 6 ms 2636 KB
large_m_2 AC 6 ms 2636 KB
large_r_0 AC 6 ms 2632 KB
large_r_1 AC 5 ms 2304 KB
large_r_2 AC 5 ms 2304 KB
large_r_3 AC 6 ms 2684 KB
large_r_4 AC 5 ms 2304 KB
large_r_5 AC 5 ms 2176 KB
large_r_6 AC 6 ms 2684 KB
large_r_7 AC 5 ms 1920 KB
large_r_8 AC 6 ms 2684 KB
large_r_9 AC 5 ms 2304 KB
large_s0_0 AC 4 ms 1920 KB
large_s0_1 AC 4 ms 1920 KB
large_s0_2 AC 5 ms 2048 KB
large_s1_0 AC 4 ms 1920 KB
large_s1_1 AC 4 ms 1920 KB
large_s1_2 AC 4 ms 1920 KB
sample_01 AC 4 ms 1792 KB
sample_02 AC 4 ms 1792 KB
small_0_0 AC 4 ms 1792 KB
small_1_0 AC 4 ms 1792 KB
small_a_0 AC 4 ms 1792 KB
small_a_1 AC 4 ms 1792 KB
small_a_2 AC 4 ms 1792 KB
small_b0_0 AC 4 ms 1792 KB
small_b0_1 AC 4 ms 1792 KB
small_b0_2 AC 4 ms 1792 KB
small_b1_0 AC 4 ms 1792 KB
small_b1_1 AC 4 ms 1792 KB
small_b1_2 AC 4 ms 1792 KB
small_r_0 AC 4 ms 1792 KB
small_r_1 AC 4 ms 1792 KB
small_r_2 AC 4 ms 1792 KB
small_r_3 AC 4 ms 1792 KB
small_r_4 AC 4 ms 1792 KB
small_r_5 AC 4 ms 1792 KB
small_r_6 AC 4 ms 1792 KB
small_r_7 AC 4 ms 1792 KB
small_r_8 AC 4 ms 1792 KB
small_r_9 AC 4 ms 1792 KB
small_s0_0 AC 4 ms 1792 KB
small_s0_1 AC 5 ms 1792 KB
small_s0_2 AC 4 ms 1792 KB
small_s1_0 AC 4 ms 1792 KB
small_s1_1 AC 4 ms 1792 KB
small_s1_2 AC 4 ms 1792 KB