Submission #1001321

# Submission time Handle Problem Language Result Execution time Memory
1001321 2024-06-18T19:08:34 Z mostafa133 Ekoeko (COCI21_ekoeko) C++14
110 / 110
52 ms 7900 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(x) x.begin(), x.end()
#define pll pair<ll, ll>
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
const ll mod = 998244353;
ld fpow(ll a, ll b, ll m = -1)
{
	if (m != -1)
		a %= m;
	ll res = 1;
	while (b > 0)
	{
		if (b % 2 == 1)
		{
			if (m != -1)
				res = res * a % m;
			else
			{
				res *= a;
			}
		}
		a = a * a;
		if (m != -1)
		{
			a %= m;
		}
		b /= 2;
	}
	return res;
}
int main()
{
	fast;
	// freopen("pails.in", "r", stdin);
	// freopen("pails.out", "w", stdout);
	ll t = 1;
	// cin >> t;
	while (t--)
	{
		ll n;
		cin >> n;
		string s;
		cin >> s;
		vector<ll> freq(200);
		for (int i = 0; i < 2 * n; i++)
		{
			freq[s[i]]++;
		}
		string s2, t;
		vector<ll> freq2(200);
		ll ans = 0;
		for (int i = 0; i < 2 * n; i++)
		{
			freq2[s[i]]++;
			if (freq2[s[i]] > freq[s[i]] / 2)
			{
				t.push_back(s[i]);
			}
			else
			{
				s2.push_back(s[i]);
				ans+=t.size();
			}
		}

		// cout << t << ' ';
		vector<set<ll>> v(200);
		for (int i = 0; i < n; i++)
		{
			v[t[i]].insert(i);
		}
		ordered_set os;
		for (int i = 0; i < n; i++)
		{
			// if (v[s[i]].empty())
			// continue;
			os.insert(*v[s2[i]].begin());
			ans += (*v[s2[i]].begin()) - os.order_of_key(*v[s2[i]].begin());
			// cout << ans << ' ';
			v[s2[i]].erase(v[s2[i]].begin());
		}
		cout << ans << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 15 ms 2836 KB Output is correct
3 Correct 34 ms 5080 KB Output is correct
4 Correct 48 ms 7136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 15 ms 2836 KB Output is correct
3 Correct 34 ms 5080 KB Output is correct
4 Correct 48 ms 7136 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 15 ms 2836 KB Output is correct
3 Correct 34 ms 5080 KB Output is correct
4 Correct 48 ms 7136 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 49 ms 7776 KB Output is correct
7 Correct 42 ms 7628 KB Output is correct
8 Correct 44 ms 7580 KB Output is correct
9 Correct 45 ms 7656 KB Output is correct
10 Correct 44 ms 7388 KB Output is correct
11 Correct 48 ms 7376 KB Output is correct
12 Correct 40 ms 7132 KB Output is correct
13 Correct 44 ms 7136 KB Output is correct
14 Correct 52 ms 7136 KB Output is correct
15 Correct 48 ms 7132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 484 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 15 ms 2836 KB Output is correct
3 Correct 34 ms 5080 KB Output is correct
4 Correct 48 ms 7136 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 49 ms 7776 KB Output is correct
11 Correct 42 ms 7628 KB Output is correct
12 Correct 44 ms 7580 KB Output is correct
13 Correct 45 ms 7656 KB Output is correct
14 Correct 44 ms 7388 KB Output is correct
15 Correct 48 ms 7376 KB Output is correct
16 Correct 40 ms 7132 KB Output is correct
17 Correct 44 ms 7136 KB Output is correct
18 Correct 52 ms 7136 KB Output is correct
19 Correct 48 ms 7132 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 484 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 47 ms 7756 KB Output is correct
33 Correct 46 ms 7900 KB Output is correct
34 Correct 43 ms 7648 KB Output is correct
35 Correct 42 ms 7644 KB Output is correct
36 Correct 45 ms 7564 KB Output is correct
37 Correct 41 ms 7392 KB Output is correct
38 Correct 49 ms 7396 KB Output is correct
39 Correct 44 ms 7284 KB Output is correct
40 Correct 42 ms 7300 KB Output is correct
41 Correct 45 ms 7108 KB Output is correct