We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 62181ff commit d36130eCopy full SHA for d36130e
ABC_162_D.cpp
@@ -0,0 +1,54 @@
1
+#include <iostream>
2
+#include <string>
3
+using namespace std;
4
+
5
+int main() {
6
+ int n;
7
+ string s;
8
+ long long result;
9
10
+ cin >> n >> s;
11
12
+ // step 1, count rgb triplets
13
+ long long cntR = 0, cntG = 0, cntB = 0;
14
15
+ for (int i = 0; i < n; i++)
16
+ {
17
+ if (s[i] == 'R')
18
19
+ cntR++;
20
+ }
21
+ else if (s[i] == 'G')
22
23
+ cntG++;
24
25
+ else
26
27
+ cntB++;
28
29
30
31
+ result = cntR * cntG * cntB;
32
33
+ // step 2, count j-i == k-j
34
35
36
+ for (int offset = 1; offset < n; offset++)
37
38
+ int j = i + offset;
39
+ int k = j + offset;
40
41
+ if (k >= n)
42
43
+ continue;
44
45
46
+ if (s[i] != s[j] && s[j] != s[k] && s[i] != s[k])
47
48
+ result--;
49
50
51
52
53
+ cout << result << endl;
54
+}
0 commit comments