# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
231722 | mohamedsobhi777 | Arranging Shoes (IOI19_shoes) | C++14 | 40 ms | 3320 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>
#include "shoes.h"
using namespace std ;
const int N =1e5 + 7 ;
int n;
long long count_swaps(std::vector<int> s) {
int val = abs(s[0]) ;
n = s.size() ;
int ret = 0 ;
for(int i = 0 ; i < n ;i++){
s[i] = (s[i] > 0) ;
}
deque<int> dq ;
int l = 1 ;
int x = 0 ;
for(int i = 0 ;i < n;i++){
if(s[i] == 1 - l){
ret+= abs(i - x++) ;
l = 1 - l ;
}
else{
dq.push_back(i) ;
}
while(dq.size() && s[dq.front()] == 1 - l){
ret+=abs(dq.front() - x++) ;
dq.pop_front() ;
l = 1 - l ;
}
}
return ret / 2;
}
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... |