# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
535038 | devariaota | Arranging Shoes (IOI19_shoes) | C++17 | 1110 ms | 408900 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;
long long count_swaps(vector<int> s) {
int tracker[s.size()+1][3];
queue <int> posi[s.size()+1][3];
bool dapat[s.size()+1];
memset(dapat, false, sizeof(dapat));
memset(tracker, 0, sizeof(tracker));
long long total2 = 0;
for(int i = 0; i<s.size(); i++) {
if(s[i] < 0) {
if(tracker[abs(s[i])][2] > 0) {
tracker[abs(s[i])][2]--;
int b = i;
int a = posi[abs(s[i])][2].front();
posi[abs(s[i])][2].pop();
int total1 = 0;
for(int i = a+1; i<b; i++) if(!dapat[i]) total1++;
total2 += b-a-total1;
dapat[a] = true;
dapat[b] = true;
}
else {
tracker[abs(s[i])][1]++;
posi[abs(s[i])][1].push(i);
}
}
else {
if(tracker[abs(s[i])][1] > 0) {
tracker[abs(s[i])][1]--;
int a = i;
int b = posi[abs(s[i])][1].front(); posi[abs(s[i])][1].pop();
int total1 = 0;
for(int i = b+1; i<a; i++) if(!dapat[i]) total1++;
total2 += a-b-1-total1;
dapat[a] = true;
dapat[b] = true;
}
else {
tracker[abs(s[i])][2]++;
posi[abs(s[i])][2].push(i);
}
}
}
return total2;
}
/*
int main() {
int n;
cin >> n;
vector<int> vec;
for(int i = 1; i<=n; i++) {
int a;
cin >> a;
vec.push_back(a);
}
cout << count_swaps(vec) << endl;
}
*/
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |