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