Submission #19540034


Source Code Expand

Copy
// #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long

const ll p = 1e9 + 7;

ll ans = 1;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	string s;
	cin >> n >> s;
	if (s[0] != 'B') {
		cout << 0;
		return 0;
	}
	int t = 1, pre = 1;
	for (int i = 1; i < s.size(); ++i) {
		if (s[i] == s[i - 1]) {
			pre = 1 - pre;
		}
		if (pre == 1) {
			t++;
		} else {
			ans = (ans * t) % p;
			t--;
			if (t < 0) {
				cout << 0;
				return 0;
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		ans = ans * i % p;
	}
	if (t) {
		cout << 0;
		return 0;
	}
	cout << ans;
}

Submission Info

Submission Time
Task C - Cell Inversion
User Cervidae
Language C++ (GCC 9.2.1)
Score 500
Code Size 685 Byte
Status AC
Exec Time 8 ms
Memory 3736 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:23:20: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   23 |  for (int i = 1; i < s.size(); ++i) {
      |                  ~~^~~~~~~~~~

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 8 ms 3532 KB
sample_02 AC 2 ms 3580 KB
sample_03 AC 2 ms 3532 KB
testcase_01 AC 3 ms 3736 KB
testcase_02 AC 3 ms 3648 KB
testcase_03 AC 3 ms 3656 KB
testcase_04 AC 3 ms 3688 KB
testcase_05 AC 5 ms 3716 KB
testcase_06 AC 4 ms 3652 KB
testcase_07 AC 5 ms 3720 KB
testcase_08 AC 7 ms 3652 KB
testcase_09 AC 5 ms 3716 KB
testcase_10 AC 2 ms 3612 KB
testcase_11 AC 2 ms 3712 KB
testcase_12 AC 3 ms 3648 KB
testcase_13 AC 8 ms 3652 KB
testcase_14 AC 8 ms 3656 KB
testcase_15 AC 5 ms 3552 KB
testcase_16 AC 3 ms 3712 KB
testcase_17 AC 4 ms 3648 KB
testcase_18 AC 5 ms 3672 KB
testcase_19 AC 6 ms 3580 KB
testcase_20 AC 3 ms 3672 KB
testcase_21 AC 8 ms 3548 KB
testcase_22 AC 5 ms 3644 KB
testcase_23 AC 4 ms 3592 KB
testcase_24 AC 5 ms 3584 KB
testcase_25 AC 8 ms 3596 KB
testcase_26 AC 2 ms 3532 KB
testcase_27 AC 2 ms 3604 KB
testcase_28 AC 6 ms 3592 KB
testcase_29 AC 3 ms 3680 KB
testcase_30 AC 4 ms 3648 KB
testcase_31 AC 4 ms 3656 KB
testcase_32 AC 5 ms 3584 KB
testcase_33 AC 5 ms 3716 KB