# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98785 | bogdan10bos | Growing Vegetable is Fun 3 (JOI19_ho_t3) | C++14 | 1055 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
//#define FILE_IO
typedef pair<int, int> pii;
int N;
string s;
vector<pii> v;
int main()
{
#ifdef FILE_IO
freopen("1.in", "r", stdin);
//freopen("1.out", "w", stdout);
#endif
cin >> N;
cin >> s;
for(int i = 0; i < N; i++)
v.push_back({s[i], i});
for(int i = 1; i < N; i++)
{
if(v[i].first != v[i - 1].first) continue;
for(int j = i + 1; j < N; j++)
if(v[j].first != v[i].first)
{
while(j > i)
{
swap(v[j], v[j - 1]);
j--;
}
break;
}
}
for(int i = N - 1; i > 0; i--)
{
if(v[i].first != v[i - 1].first) continue;
for(int j = i - 2; j >= 0; j--)
if(v[j].first != v[i].first)
{
while(j < i - 1)
{
swap(v[j], v[j + 1]);
j++;
}
}
}
int ans = 0;
for(int i = 0; i < v.size(); i++)
if(v[i].second > i)
ans += v[i].second - i;
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |