답안 #1001315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001315 2024-06-18T18:52:56 Z mostafa133 Ekoeko (COCI21_ekoeko) C++14
0 / 110
1000 ms 344 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;
		string t = s.substr(n, n);
		// cout << t << ' ';
		vector<set<ll>> v(200);
		for (int i = 0; i < n; i++)
		{
			v[t[i]].insert(i);
		}
		sort(all(t));
		string t1 = s.substr(0, n);
		sort(all(t1));
		if(t!=t1)cout << 0;
		ordered_set os;
		ll ans = 0;
		for (int i = 0; i < n; i++)
		{
			// if (v[s[i]].empty())
				// continue;
			os.insert(*v[s[i]].begin());
			ans += (*v[s[i]].begin()) - os.order_of_key(*v[s[i]].begin());
			// cout << ans << ' ';
			v[s[i]].erase(v[s[i]].begin());
		}
		cout << ans << '\n';
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1040 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1040 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1040 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 1048 ms 344 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1040 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -