Skip to content

Commit fcbb4c5

Browse files
Create G037-B.cpp
1 parent 6b691dd commit fcbb4c5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

AtCoder/G037-B.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
const int mxN=1e5, M=998244353;
5+
int n, a[3*mxN], d[4];
6+
string s;
7+
map<char, int> mp{{'R', 0}, {'G', 1}, {'B', 2}};
8+
vector<int> v[3];
9+
long long ans=1;
10+
11+
int main() {
12+
ios::sync_with_stdio(0);
13+
cin.tie(0);
14+
15+
cin >> n >> s;
16+
for(int i=0; i<3*n; ++i)
17+
v[mp[s[i]]].push_back(i);
18+
for(int i=0; i<n; ++i) {
19+
a[min({v[0][i], v[1][i], v[2][i]})]=-1;
20+
a[max({v[0][i], v[1][i], v[2][i]})]=1;
21+
}
22+
d[0]=n;
23+
for(int i=0; i<3*n; ++i) {
24+
ans=ans*d[a[i]+1]%M;
25+
--d[a[i]+1];
26+
++d[a[i]+2];
27+
}
28+
cout << ans;
29+
}

0 commit comments

Comments
 (0)