Submission #601639

#TimeUsernameProblemLanguageResultExecution timeMemory
601639Minindu2006Arranging Shoes (IOI19_shoes)C++14
65 / 100
1085 ms2988 KiB
#include "shoes.h" #include <bits/stdc++.h> #define ll long long using namespace std; ll count_swaps(vector<int> s) { ll n = s.size() / 2; if (n == 1) return s[0] > 0; int isb4 = 1; for (int i = 0; i < n; i++) { if (s[i] != -s[i + n] || s[i] > 0) { isb4 = 0; break; } } if (isb4) return n * (n - 1) / 2; ll pos = 0, ans = 0; while (pos < 2 * n) { if (s[pos] > 0) { int i; for (i = pos + 1; i < 2 * n; i++) if (s[i] == -s[pos]) break; int num = s[i]; s.erase(s.begin() + i); s.insert(s.begin() + pos, num); ans += (i - pos); } else if (s[pos] + s[pos + 1] != 0) { int i; for (i = pos + 2; i < 2 * n; i++) if (s[i] == -s[pos]) break; int num = s[i]; s.erase(s.begin() + i); s.insert(s.begin() + pos + 1, num); ans += (i - pos - 1); } // cout << s[pos] << " " << s[pos + 1] << '\n'; pos += 2; } return ans; }
#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...