Submission #19550853


Source Code Expand

Copy
#include <iostream>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

using mint = modint1000000007;

int main() {
	int N;
	string S;
	cin >> N >> S;
	N *= 2;
	if (S.front() == 'W' || S.back() == 'W') {
		cout << 0 << endl;
		return 0;
	}
	vector<int>LR(N, 0);
	LR.back() = 1;
	int right = 1;
	for (int i = 1; i < N - 1; i++) {
		LR[i] = (S[i] == S[i - 1] ? 1 - LR[i - 1] : LR[i - 1]);
		right += LR[i];
	}
	if (right != N / 2) {
		cout << 0 << endl;
		return 0;
	}

	mint ans = 1;
	int num = 0;
	for (int i = 0; i < N; i++) {
		if (LR[i]) {
			ans *= num;
			num--;
		}
		else num++;
	}
	for (int i = 1; i <= N / 2; i++) ans *= i;
	cout << ans.val() << endl;
}

Submission Info

Submission Time
Task C - Cell Inversion
User AsamiCrayon
Language C++ (GCC 9.2.1)
Score 500
Code Size 722 Byte
Status AC
Exec Time 17 ms
Memory 4480 KB

Judge Result

Set Name All Sample
Score / Max Score 500 / 500 0 / 0
Status
AC × 36
AC × 3
Set Name Test Cases
All sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_19, testcase_20, testcase_21, testcase_22, testcase_23, testcase_24, testcase_25, testcase_26, testcase_27, testcase_28, testcase_29, testcase_30, testcase_31, testcase_32, testcase_33
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 AC 4 ms 3572 KB
sample_02 AC 3 ms 3468 KB
sample_03 AC 3 ms 3516 KB
testcase_01 AC 8 ms 3660 KB
testcase_02 AC 12 ms 3684 KB
testcase_03 AC 11 ms 3628 KB
testcase_04 AC 5 ms 3568 KB
testcase_05 AC 7 ms 3840 KB
testcase_06 AC 5 ms 3720 KB
testcase_07 AC 14 ms 4024 KB
testcase_08 AC 12 ms 4388 KB
testcase_09 AC 10 ms 4388 KB
testcase_10 AC 2 ms 3616 KB
testcase_11 AC 4 ms 3760 KB
testcase_12 AC 8 ms 3648 KB
testcase_13 AC 17 ms 4480 KB
testcase_14 AC 14 ms 4148 KB
testcase_15 AC 11 ms 4420 KB
testcase_16 AC 8 ms 3792 KB
testcase_17 AC 12 ms 3984 KB
testcase_18 AC 11 ms 4152 KB
testcase_19 AC 8 ms 4212 KB
testcase_20 AC 6 ms 3716 KB
testcase_21 AC 9 ms 4288 KB
testcase_22 AC 11 ms 4416 KB
testcase_23 AC 6 ms 3732 KB
testcase_24 AC 9 ms 4368 KB
testcase_25 AC 12 ms 4368 KB
testcase_26 AC 2 ms 3572 KB
testcase_27 AC 3 ms 3628 KB
testcase_28 AC 14 ms 4480 KB
testcase_29 AC 8 ms 3740 KB
testcase_30 AC 10 ms 4400 KB
testcase_31 AC 7 ms 3700 KB
testcase_32 AC 7 ms 3684 KB
testcase_33 AC 12 ms 3792 KB