# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
153787 | asifthegreat | Arranging Shoes (IOI19_shoes) | C++14 | 1085 ms | 8668 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;
#include "shoes.h"
const int N = 300000;
long long subtask3(std::vector<int>s){
set<int>st;
for(auto i: s)st.insert(abs(i));
if(st.size() != 1)return 0ll;
vector<int> v;
for(int i=0;i<s.size();i++){
if(s[i]<0)v.push_back(i);
}
long long now=0,ans=0;
for(int i=0;i<s.size();i++){
if(i%2==0){
ans+=abs(v[now]-i);
now++;
}
}
return ans;
// return ans;
}
long long count_swaps(std::vector<int> s) {
int n = s.size();
if(true){
long long ans_3 = subtask3(s);
if(ans_3)return ans_3;
}
if(true){
int papa = n/2;
bool ok = true;
for(int i = 0; i < papa;i++){
if(s[i] == -s[i+papa] and s[i] < 0)continue;
ok = false;break;
}
if(ok){
long long nn = (int)s.size()/2ll;
return nn*(nn-1ll)/2ll;
}
}
int cnt = 0;
for(int i = 0; i < n;i+=2){
int k = -69;
for(int j = i+1; j < n;j++){
if(s[i] == -s[j]){k = j;break;}
}
while(k != i+1){
swap(s[k],s[k-1]);
k--;
cnt++;
}
if(s[i] > 0){
swap(s[i],s[i+1]);cnt++;
}
}
return cnt;
}
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... |