Submission #219761

#TimeUsernameProblemLanguageResultExecution timeMemory
219761VEGAnnArranging Shoes (IOI19_shoes)C++14
65 / 100
36 ms2296 KiB
#include <bits/stdc++.h> #include "shoes.h" #define all(x) x.begin(),x.end() #define PB push_back #define sz(x) ((int)x.size()) using namespace std; typedef long long ll; const int N = 100100; long long count_swaps(std::vector<int> s) { if (sz(s) <= 2000) { int n = sz(s) / 2; ll ans = 0; for (int i = 0; i < n; i++){ int loc = i + i; int pos = -1; for (int j = loc + 1; j < sz(s); j++) if (s[j] == -s[loc]){ pos = j; break; } assert(pos >= 0); while (pos > loc + 1){ swap(s[pos], s[pos - 1]); pos--; ans++; } if (s[loc] > 0) ans++; } return ans; } else { ll n = sz(s) / 2; return n * (n - 1ll) / 2ll; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...