Atcoder Grand Contest 037B (DP, combinatorics, thinking)

#include <bits / STDC ++ H.>
the using namespace STD;
const Long Long MOD = 998 244 353;
String S;
int A [300007];
Long Long X [. 7], Y [. 7];
int main () {
int n-;
CIN n->>;
CIN >> S;
int len = s.size ();
for (int I = 0; I <len; I ++) {
IF (S [I] == 'B')
A [I] . 1 =;
the else IF (S [I] == 'G')
A [I] = 2;
}
Long = Long ANS. 1;
for (int I = 2; I <= n-; I ++)
ANS = 1LL * ans * i% mod; // every three balls may be allocated to individual n ~ 1.
for (int i = 0; i <len; ++ i) {// encounters a first color balls, the number of records which, when faced with a different color from the first color balls optionally a simultaneously record the number of second color balls, encountered when the third color, second color, optionally from a sphere.
// number of color where a first ball is x [a [i]] stored, the number of second color sphere is the presence of y [(a [i] + 1or2)% 3] in when confronted with a third color that is (a [i] + 1or2) % 3 when optionally from a second color balls
if (y [a [i] ]) // i preceded y [a [i]] a (a [i] +2)% 3 colored balls from the front of the face i y [a [i] ] of a select
ANS ANS * Y = [a [I]] -% MOD;
else if (X [(a [I] + 1'd)%. 3]) and the next // else if equivalent, the other two position the same colors, which can be encountered in combination, the three colors are equivalent
ans = ans * x [(a [i] +1)% 3] -% mod, y [(a [i ] +2)% 3] ++; // preceded x [(a [i] +1 )% 3] a (a [i] +1)% 3 colored balls from the face i x [ (a [i] +1) select a% 3] of the
else if (x [(a [ i] +2)% 3]) // else if and one equivalent, the same two colors other status, encountered of which may be combined where three colors are equivalent
ans = ans * x [(a [i] +2)% 3] -% mod, y [(a [i] +1)% 3 ] ++; // preceded x [(a [i] +2 )% 3] a (a [i] +2)% 3 colored balls from the face i x [(a [i] + 2) 3%] of a select
the else
X [a [i]] ++; // record the current number of balls of a [i] color
}
COUT << ANS;
return 0;
}

Guess you like

Origin www.cnblogs.com/ldudxy/p/11371526.html