Submission #1003943

# Submission time Handle Problem Language Result Execution time Memory
1003943 2024-06-20T20:39:57 Z vjudge1 Ekoeko (COCI21_ekoeko) C++17
20 / 110
5 ms 3264 KB
#include <bits/stdc++.h>

using namespace std;
using lli = long long;

const int MAXN = 1e5 + 10;

int bit[MAXN];

void add(int idx, int x, int n) {
	for (; idx < n; idx = idx | (idx + 1))
		bit[idx] += x;
}

int pref(int idx) {
	int sum = 0;
	for (; idx >= 0; idx = (idx & (idx + 1)) - 1)
		sum += bit[idx];

	return sum;
}

int sum(int l, int r) { return pref(r) - pref(l-1); }

int main() {
	int n;
	cin >> n;

	n *= 2;

	string s;
	cin >> s;

	vector<vector<int>> cnt(26);
	for (int i = 0; i < n; ++i)
		cnt[s[i] - 'a'].push_back(i);

	vector<int> perm(n);
	int atual = 0; string final;
	vector<int> cnt2(26);
	for (int i = 0; i < n; ++i) {
		int c = s[i] - 'a';
		if (cnt2[c] < cnt[c].size()/2) {
			++cnt2[c];
			perm[i] = atual++;
			final.push_back(s[i]);
		}
	}
	
	for (char c: final)
		perm[cnt[c - 'a'][cnt2[c - 'a']++]] = atual++;

	lli ans = 0;
	for (int i = 0; i < n; ++i) {
		ans += sum(perm[i], n);
		add(perm[i], 1, n);
	}

	cout << ans << "\n";
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:43:15: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   if (cnt2[c] < cnt[c].size()/2) {
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 1432 KB Output is correct
3 Runtime error 5 ms 3264 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 1432 KB Output is correct
3 Runtime error 5 ms 3264 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 1432 KB Output is correct
3 Runtime error 5 ms 3264 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 3 ms 1432 KB Output is correct
3 Runtime error 5 ms 3264 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -