This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n")
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vv vector
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int inf = 2e09; ll infll = 2e18; int mod = 119<<23|1;
ll count_swaps(vv<int> t){
int n = ssize(t)/2;
ll result = 0;
for(int i = 0; i < n<<1; i += 2){
int st = i+1;
for(int j = i+1; j < n<<1; ++j) if(abs(t[j]) == abs(t[i])){ st = j; break; }
if(t[i] < 0)
for(int j = st-1; j > i; --j) swap(t[j+1], t[j]), ++result;
else
for(int j = st-1; j >= i; --j) swap(t[j+1], t[j]), ++result;
}
return result;
}
#ifdef LOCAL
int main(){
int T = 1;
for(++T; --T; ){
int n; scanf("%d", &n);
vv<int> t(n<<1);
for(int i = 0; i < n<<1; ++i) scanf("%d", &t[i]);
ll result = count_swaps(t);
printf("%lld\n", result);
}
return 0;
}
#endif
# | 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... |