이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#ifdef ONPC
#include"debug.h"
#else
#define debug(...) 42
#endif
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
const int mod = 1e9 + 7;
const int MAXN = 1e6 + 15;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
long long count_swaps(vector<int> S){
auto a = S;
sort(all(a));
int n = sz(a);
vector<int> brut;
ll ans = 1e18;
do {
brut = S;
bool good = 1;
for (int i = 1; i < n; i += 2){
good &= a[i] + a[i - 1] == 0;
good &= a[i] > a[i - 1];
}
ll cost = 0;
for (int i = 0; i < n; i++){
if (a[i] == brut[i]) continue;
for (int j = i; j < n; j++){
if (a[i] == brut[j]){
for (int k = j; k > i; k--){
cost++;
swap(brut[k], brut[k - 1]);
}
break;
}
}
}
if (good) ckmin(ans, cost);
} while (next_permutation(all(a)));
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... |