Wrong Answer
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