Submission #692297

#TimeUsernameProblemLanguageResultExecution timeMemory
692297Farhan_HYEkoeko (COCI21_ekoeko)C++14
10 / 110
39 ms2520 KiB
#include <bits/stdc++.h> #define int long long #define float double #define pb push_back #define F first #define S second #define T int t; cin >> t; while(t--) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; /// Benzema is the best player in the world const int N = 1e6 + 6; const int M = 1e3 + 3; const int mod = 1e9 + 7; const int inf = 1e9; const int dx[] = {-1, 1, 0, 0}; const int dy[] = {0, 0, -1, 1}; const int LOG = 28; int n, cnt[LOG]; bool vis[N]; deque<int> pos[LOG]; string s; main() { IOS cin >> n >> s; n *= 2; for(int i = 0; i < n; i++) cnt[s[i] - 'a']++, pos[s[i] - 'a'].push_back(i); for(int i = 0; i < 26; i++) cnt[i] /= 2; string s1, s2; int ans = 0; for(int i = 0; i < n / 2; i++) { int c = -1; for(int j = 0; j < 26; j++) { if (cnt[j] == 0 || pos[j].size() == 0) continue; if (c == -1 || pos[j].front() < pos[c].front()) c = j; } cnt[c]--; vis[pos[c].front()] = 1; ans += pos[c].front() - i; pos[c].pop_front(); s1 += (c + 'a'); } for(int i = 0; i < n; i++) if (!vis[i]) s2 += s[i]; for(int i = 0; i < 26; i++) pos[i].clear(); n /= 2; for(int i = 0; i < n; i++) pos[s2[i] - 'a'].push_back(i); multiset<int> st; for(int i = 0; i < n; i++) { int idx = pos[s1[i] - 'a'].front(); idx += st.size(); ans += max(0ll, idx - i); st.insert(idx); pos[s1[i] - 'a'].pop_front(); st.erase(*st.find(i)); } cout << ans; }

Compilation message (stderr)

Main.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   24 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...