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 <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cassert>
#include <tuple>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef vector<int> Vi;
typedef vector<bool> Vb;
typedef vector<vector<int>> Vii;
#define forR(i, n) for (int i = 0; i < (n); i++)
LL count_swaps(Vi S) {
int n = S.size() / 2;
LL ans = 0;
forR(i, n) {
int p = i * 2;
int Sp = S[p];
int q = p + 1;
while (S[q] != -Sp) q++;
while (q > p + 1) {
swap(S[q], S[q - 1]);
q--;
ans++;
}
if (S[p] > 0) ans++;
}
return ans;
}
#ifdef TEST_LOCAL
int main() {
auto c = count_swaps(Vi{ 2, 1, -1, -2 });
c = count_swaps(Vi{ -2, 2, 2, -2, -2, 2 });
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... |