이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
using namespace std;
ll count_swaps(vi s) {
int n = s.size(), ans = 0;
for(int i = 0; i < n; ++i) {
if(i % 2) {
int j = i;
while(s[j] != -s[i - 1])
j++;
while(j != i) {
swap(s[j], s[j - 1]);
ans++;
j--;
}
}
else if(s[i] > 0) {
int j1 = i;
while(s[j1] > 0)
j1++;
int j2 = i;
while(s[j2] != -s[i])
j2++;
int j3 = i;
while(s[j3] != -s[j1])
j3++;
int j = ((j2 - i) < (j1 - i + j3 - i)) ? j2 : j1;
while(j != i) {
swap(s[j], s[j - 1]);
ans++;
j--;
}
}
}
return ans;
}
# | 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... |