/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Wrong Answer 5ms 1.016 MiB
#3 Wrong Answer 2ms 324.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        string str;
        cin >> str;

        vector<int> ones;
        vector<int> zeros;
        int d = 0;
        for (int i = 0; i < n; i++)
        {
            if (str[i] == '1')
            {
                ones.push_back(i);
            }
            else
            {
                zeros.push_back(i);
            }
        }

        int mO = ones.size();
        int mZ = zeros.size();
        int operations_ones = 0;
        for (int j = 0; j < mO; j++)
        {
            operations_ones += abs(ones[j] - j);
        }

        for (int i = 0; i < mZ; i++)
        {
            d = d + abs(zeros[i] - i);
        }

        cout << min(operations_ones, d) << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1016 Swap sort
Contest
Brain booster - 1
Language
C++20 (G++ 13.2.0)
Submit At
2023-12-31 14:39:26
Judged At
2024-11-11 03:46:11
Judged By
Score
20
Total Time
5ms
Peak Memory
1.016 MiB