이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
//#include "fish.h"
#include <iostream>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
const int N = 1000 + 10, M = 110;
bool used[N];
ll count_swaps(vector<int> S) {
int n = (int)S.size() / 2;
vector <int> v;
for (auto &it : S) {
if (it > 0) v.push_back(it);
}
sort(v.begin(), v.end());
int ans = 0;
vector <int> s = S;
for (int j = 0; j < (int)v.size(); j++) {
for (int i = 2 * j; i < 2 * n; i++) {
if (v[j] == -s[i]) {
for (int k = i; k > 2 * j; k--) {
swap(s[k], s[k - 1]);
}
ans += abs(i - 2 * j);
break;
}
}
for (int i = 2 * j + 1; i < 2 * n; i++) {
if (v[j] == s[i]) {
for (int k = i; k > 2 * j + 1; k--) {
swap(s[k], s[k - 1]);
}
ans += abs(i - 2 * j - 1);
break;
}
}
}
//cout << ans << "\n";
while (next_permutation(v.begin(), v.end())) {
int cur_ans = 0;
vector <int> s = S;
for (int j = 0; j < (int)v.size(); j++) {
for (int i = 2 * j; i < 2 * n; i++) {
if (v[j] == -s[i]) {
for (int k = i; k > 2 * j; k--) {
swap(s[k], s[k - 1]);
}
cur_ans += abs(i - 2 * j);
break;
}
}
for (int i = 2 * j + 1; i < 2 * n; i++) {
if (v[j] == s[i]) {
for (int k = i; k > 2 * j + 1; k--) {
swap(s[k], s[k - 1]);
}
cur_ans += abs(i - 2 * j - 1);
break;
}
}
}
ans = min(ans, cur_ans);
}
//cout << ans << "\n";
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... |