Submission #7119718


Source Code Expand

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std ;

const long long mod = 1e9 + 7ll ;

const int MAX = 2e5 + 5 ;

int n ;

int add(int x , int y)
{
	if(x >= mod)
		x -= mod ;
	if(y >= mod)
		y -= mod ;
	int z = x+y ;
	if(z >= mod)
		z -= mod ;
	return z ;
}

int arr[MAX] ;
string s ;

int main()
{
	//ios_base::sync_with_stdio(0) ;
	//cin.tie(0) ;
	cin>>n ;
	cin>>s ;
	for(int i = 0 ; i < n*2 ; ++i)
	{
		if(s[i] == 'W')
			arr[i] = 0 ;
		else
			arr[i] = 1 ;
	}
	long long ans = 1ll ;
	long long moves = 0 ;
	if(arr[0] == 0)
		return cout<<0<<"\n" , 0 ;
	for(int i = 0 ; i < n*2 ; ++i)
	{
		if((arr[i] + moves) % 2 != 0)
			moves++ ;
		else
		{
			ans = (ans * moves) % mod ;
			ans %= mod ;
			moves-- ;
		}
		if(moves > n || moves < 0)
			return cout<<0<<"\n" , 0 ;
	}
	if(moves != 0)
		return cout<<0<<"\n" , 0 ;
	long long fact = 1ll ;
	for(int i = 2 ; i <= n ; ++i)
	{
		fact = (fact * i) % mod ;
		fact %= mod ;
	}
	ans = (ans * fact) % mod ;
	ans %= mod ;
	return cout<<ans<<"\n" , 0;
}

Submission Info

Submission Time
Task C - Cell Inversion
User MohamedAhmed04
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1127 Byte
Status AC
Exec Time 9 ms
Memory 1284 KiB

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 1 ms 256 KiB
sample_02 AC 1 ms 256 KiB
sample_03 AC 1 ms 256 KiB
testcase_01 AC 5 ms 1024 KiB
testcase_02 AC 5 ms 896 KiB
testcase_03 AC 8 ms 1284 KiB
testcase_04 AC 3 ms 512 KiB
testcase_05 AC 5 ms 896 KiB
testcase_06 AC 4 ms 768 KiB
testcase_07 AC 7 ms 1028 KiB
testcase_08 AC 9 ms 1284 KiB
testcase_09 AC 9 ms 1284 KiB
testcase_10 AC 2 ms 384 KiB
testcase_11 AC 4 ms 768 KiB
testcase_12 AC 8 ms 1284 KiB
testcase_13 AC 9 ms 1284 KiB
testcase_14 AC 7 ms 1028 KiB
testcase_15 AC 8 ms 1284 KiB
testcase_16 AC 5 ms 896 KiB
testcase_17 AC 8 ms 1284 KiB
testcase_18 AC 7 ms 1156 KiB
testcase_19 AC 7 ms 1156 KiB
testcase_20 AC 4 ms 768 KiB
testcase_21 AC 9 ms 1284 KiB
testcase_22 AC 9 ms 1284 KiB
testcase_23 AC 5 ms 896 KiB
testcase_24 AC 9 ms 1284 KiB
testcase_25 AC 9 ms 1284 KiB
testcase_26 AC 1 ms 256 KiB
testcase_27 AC 1 ms 256 KiB
testcase_28 AC 9 ms 1284 KiB
testcase_29 AC 8 ms 1284 KiB
testcase_30 AC 9 ms 1284 KiB
testcase_31 AC 8 ms 1284 KiB
testcase_32 AC 8 ms 1284 KiB
testcase_33 AC 8 ms 1284 KiB