#include "shoes.h"
#include <bits/stdc++.h>
#include <cstdio>
#include <cassert>
#define pb push_back
using namespace std;
int n;
vector<int> tike[200005][2];
int dokle[200005][2];
long long count_swaps(std::vector<int> s) {
n = s.size()/2;
long long pom = n;
pom = pom * (pom - 1);
pom /= 2;
return pom;
for(int i=0; i<2*n; i++){
if(s[i] < 0)tike[abs(s[i])][0].pb(i);
else tike[s[i]][1].pb(i);
}
int l = 0;
long long res = 0;
while(l < 2*n){
int koji = abs(s[l]);
int ind = 0;
if(s[l] < 0)ind = 1;
int gde = tike[koji][ind][dokle[koji][ind]];
while(gde > l+1){
//cout << gde << endl;
swap(s[gde], s[gde-1]);
res++;
gde--;
}
dokle[koji][ind]++;
dokle[koji][ind^1]++;
if(!ind)res++;
l += 2;
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Incorrect |
11 ms |
9720 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Incorrect |
11 ms |
9720 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Incorrect |
11 ms |
9720 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
9720 KB |
Output is correct |
2 |
Correct |
11 ms |
9720 KB |
Output is correct |
3 |
Correct |
10 ms |
9724 KB |
Output is correct |
4 |
Correct |
10 ms |
9636 KB |
Output is correct |
5 |
Correct |
40 ms |
11320 KB |
Output is correct |
6 |
Correct |
40 ms |
11260 KB |
Output is correct |
7 |
Correct |
40 ms |
11256 KB |
Output is correct |
8 |
Correct |
38 ms |
11256 KB |
Output is correct |
9 |
Correct |
39 ms |
11312 KB |
Output is correct |
10 |
Correct |
40 ms |
11256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Incorrect |
11 ms |
9720 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9720 KB |
Output is correct |
2 |
Incorrect |
11 ms |
9720 KB |
Output isn't correct |