Submission #68904729


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

using LL = long long;
#define endl '\n'
using db = double;
template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> a;
    for (int i = 0; i < n * 2; ++i)
    {
        if (s[i] == 'A')
            a.push_back(i);
    }

    LL res1 = 0, res2 = 0;
    for (int i = 0; i < n; ++i)
    {
        int j = i * 2;
        res1 += abs(a[i] - j);
    }
    for (int i = 0; i < n; ++i)
    {
        int j = i * 2 + 1;
        res2 += abs(a[i] - j);
    }
    cout << min(res1, res2);

    return 0;
}

Submission Info

Submission Time
Task C - Alternated
User hialine
Language C++ 20 (gcc 12.2)
Score 350
Code Size 796 Byte
Status AC
Exec Time 10 ms
Memory 6636 KiB

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 10 ms 6628 KiB
random_02.txt AC 8 ms 6308 KiB
random_03.txt AC 10 ms 6460 KiB
random_04.txt AC 4 ms 4668 KiB
random_05.txt AC 9 ms 6560 KiB
random_06.txt AC 5 ms 4748 KiB
random_07.txt AC 6 ms 6612 KiB
random_08.txt AC 5 ms 6536 KiB
random_09.txt AC 5 ms 6636 KiB
random_10.txt AC 5 ms 6596 KiB
random_11.txt AC 6 ms 6540 KiB
random_12.txt AC 6 ms 6532 KiB
random_13.txt AC 1 ms 3520 KiB
sample_01.txt AC 1 ms 3468 KiB
sample_02.txt AC 1 ms 3520 KiB
sample_03.txt AC 1 ms 3528 KiB