Submission #68922596


Source Code Expand

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
#include <numeric>
using namespace std;
#define ll long long
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vii vector<pair<int, int>>
#define vllvector vector<pair<ll, ll>>
#define vb vector<bool>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define rep(i, n) for (ll i = 0; i < n; i++)

int main() {
    ll n;
    string s;
    cin >> n >> s;

    vll a, b;
    rep(i, 2 * n) {
        if (s[i] == 'A') {
            a.push_back(i);
        } else {
            b.push_back(i);
        }
    }

    ll ans = 0;
    rep(i, n) {
        ans += abs(a[i] -2 * i);
    }

    ll ans_ = 0;
    rep(i, n) {
        ans_ += abs(a[i] - (2 * i+ 1));
    }

    cout<< min(ans, ans_) << endl;
}

Submission Info

Submission Time
Task C - Alternated
User kar1neko
Language C++ 20 (gcc 12.2)
Score 350
Code Size 953 Byte
Status AC
Exec Time 25 ms
Memory 14032 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 25 ms 13756 KiB
random_02.txt AC 20 ms 10372 KiB
random_03.txt AC 25 ms 13792 KiB
random_04.txt AC 9 ms 6976 KiB
random_05.txt AC 25 ms 13820 KiB
random_06.txt AC 12 ms 7536 KiB
random_07.txt AC 21 ms 13428 KiB
random_08.txt AC 20 ms 13516 KiB
random_09.txt AC 21 ms 13484 KiB
random_10.txt AC 21 ms 14032 KiB
random_11.txt AC 21 ms 12364 KiB
random_12.txt AC 22 ms 12416 KiB
random_13.txt AC 1 ms 3516 KiB
sample_01.txt AC 1 ms 3604 KiB
sample_02.txt AC 1 ms 3488 KiB
sample_03.txt AC 1 ms 3476 KiB