Submission #11858752


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N; string S;
int R = 1, G = 2, B = 4;
int RGB = 7;
int cnt[8];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> S;
	fore(c, S) {
		if (c == 'R') c = R;
		else if (c == 'G') c = G;
		else c = B;
	}

	int r = 0, g = 0, b = 0;
	ll ans = 0;
	rep(j, 0, N) {
		rep(k, j + 1, N) {
			if (S[j] == S[k]) continue;

			int Si = RGB - S[j] - S[k];
			ans += cnt[Si];

			int i = j - (k - j);
			if (0 <= i) {
				int msk = S[i] | S[j] | S[k];
				if (msk == RGB) ans--;
			}
		}

		cnt[S[j]]++;
	}
	cout << ans << endl;
}





Submission Info

Submission Time
Task D - RGB Triplets
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 400
Code Size 1916 Byte
Status AC
Exec Time 28 ms
Memory 3604 KB

Compile Error

./Main.cpp: In function ‘void _main()’:
./Main.cpp:64:11: warning: array subscript has type ‘char’ [-Wchar-subscripts]
   64 |   cnt[S[j]]++;
      |           ^
./Main.cpp:48:6: warning: unused variable ‘r’ [-Wunused-variable]
   48 |  int r = 0, g = 0, b = 0;
      |      ^
./Main.cpp:48:13: warning: unused variable ‘g’ [-Wunused-variable]
   48 |  int r = 0, g = 0, b = 0;
      |             ^
./Main.cpp:48:20: warning: unused variable ‘b’ [-Wunused-variable]
   48 |  int r = 0, g = 0, b = 0;
      |                    ^

Judge Result

Set Name All Sample
Score / Max Score 400 / 400 0 / 0
Status
AC × 21
AC × 2
Set Name Test Cases
All sample_01, sample_02, testcase_0, testcase_1, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_2, testcase_3, testcase_4, testcase_5, testcase_6, testcase_7, testcase_8, testcase_9
Sample sample_01, sample_02
Case Name Status Exec Time Memory
sample_01 AC 2 ms 3544 KB
sample_02 AC 2 ms 3600 KB
testcase_0 AC 2 ms 3540 KB
testcase_1 AC 2 ms 3604 KB
testcase_10 AC 2 ms 3528 KB
testcase_11 AC 2 ms 3532 KB
testcase_12 AC 2 ms 3532 KB
testcase_13 AC 3 ms 3480 KB
testcase_14 AC 3 ms 3484 KB
testcase_15 AC 28 ms 3548 KB
testcase_16 AC 10 ms 3552 KB
testcase_17 AC 28 ms 3580 KB
testcase_18 AC 17 ms 3592 KB
testcase_2 AC 2 ms 3516 KB
testcase_3 AC 2 ms 3584 KB
testcase_4 AC 2 ms 3532 KB
testcase_5 AC 2 ms 3592 KB
testcase_6 AC 2 ms 3492 KB
testcase_7 AC 2 ms 3544 KB
testcase_8 AC 2 ms 3492 KB
testcase_9 AC 2 ms 3492 KB