이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <vector>
#include <bitset>
#include <tuple>
#include <cmath>
using namespace std;
typedef vector<int> vi;
typedef pair<vi,bool> vib;
int n,num,shoeSize,index,first,second;
long long count_swaps(std::vector<int> s) {
n = s.size() / 2;
vib sizes[n + 1];
long long swapsNeeded = 0;
for(index = 0; index < 2 * n; ++index) {
num = s[index];
//cerr << "shoe num " << index << " is " << num << endl;
shoeSize = abs(num);
if(sizes[shoeSize].first.size() == 0) {
sizes[shoeSize].first.push_back(index);
sizes[shoeSize].second = num > 0;
} else if((num > 0) == sizes[shoeSize].second) {
sizes[shoeSize].first.push_back(index);
} else {
first = num < 0 ? index : sizes[shoeSize].first[0];
second = num > 0 ? index : sizes[shoeSize].first[0];
if(second > first) {
swapsNeeded += second - first - 1;
} else {
swapsNeeded += first - second;
}
sizes[shoeSize].first.erase(sizes[shoeSize].first.begin());
}
}
return swapsNeeded;
}
# | 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... |