이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1024;
int n;
vector <pair <int, int> > pairs;
bool used [maxn];
long long count_swaps (vector <int> s){
n = s.size ();
long long ans = 0;
for (int i = 0; i < n; i ++){
if (used [i]) continue;
used [i] = 1;
for (int j = i + 1; j < n; j ++){
if (!used [j] && s [i] + s [j] == 0){
used [j] = 1;
if (s [j] < 0) ans ++;
pairs.push_back ({i, j});
break;
}
}
}
n /= 2;
for (int i = 0; i < n; i ++){
for (int j = i + 1; j < n; j ++){
if (pairs [j].second < pairs [i].second) ans += 2;
else if (pairs [j].first < pairs [i].second) ans ++;
}
}
return ans;
}
//int main (){
//cout << count_swaps ({-2, 2, 2, -2, -2, 2}) << '\n';
//}
# | 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... |