Submission #68928261


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define int long long

int n, ans1, ans2;
string s;

signed main() {

	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);

	cin >> n;
	cin >> s;
	for (int i = 0, k = 0, j = 1; i < s.size(); i++) {
		if (s[i] == 'A')
			ans1 += abs(i - k), k += 2;
		else
			ans1 += abs(i - j), j += 2;
	}
	for (int i = 0, k = 1, j = 0; i < s.size(); i++) {
		if (s[i] == 'A')
			ans2 += abs(i - k), k += 2;
		else
			ans2 += abs(i - j), j += 2;
	}
	cout << min(ans1, ans2)/2 << endl;

	return 0;
}

Submission Info

Submission Time
Task C - Alternated
User KDL_ANIPLEX
Language C++ 20 (gcc 12.2)
Score 350
Code Size 562 Byte
Status AC
Exec Time 22 ms
Memory 5236 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:15:41: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   15 |         for (int i = 0, k = 0, j = 1; i < s.size(); i++) {
      |                                       ~~^~~~~~~~~~
Main.cpp:21:41: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   21 |         for (int i = 0, k = 1, j = 0; i < s.size(); i++) {
      |                                       ~~^~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 350 / 350
Status
AC × 3
AC × 16
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
random_01.txt AC 21 ms 5188 KiB
random_02.txt AC 17 ms 4196 KiB
random_03.txt AC 22 ms 5236 KiB
random_04.txt AC 7 ms 3804 KiB
random_05.txt AC 21 ms 5236 KiB
random_06.txt AC 10 ms 3764 KiB
random_07.txt AC 14 ms 5208 KiB
random_08.txt AC 14 ms 5228 KiB
random_09.txt AC 14 ms 5236 KiB
random_10.txt AC 16 ms 5192 KiB
random_11.txt AC 15 ms 5220 KiB
random_12.txt AC 14 ms 5192 KiB
random_13.txt AC 1 ms 3540 KiB
sample_01.txt AC 1 ms 3452 KiB
sample_02.txt AC 1 ms 3516 KiB
sample_03.txt AC 1 ms 3532 KiB