Submission #779555

#TimeUsernameProblemLanguageResultExecution timeMemory
779555Minindu206Arranging Shoes (IOI19_shoes)C++14
25 / 100
19 ms1864 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 iseq = 1; for(int i=0;i<n;i++) if(s[i] + s[i + n] != 0) { iseq = 0; break; } if(iseq) return n * (n - 1) / 2; int cur = 0; ll ans = 0LL; while(cur < 2 * n) { if(s[cur] > 0) { int i = cur + 1; while(s[i] != -s[cur]) i++; s.erase(s.begin() + i); s.insert(s.begin() + cur, -s[cur]); ans += (i - cur); } else if (s[cur] + s[cur + 1] != 0) { int i = cur + 1; while(s[i] != -s[cur]) i++; s.erase(s.begin() + i); s.insert(s.begin() + cur + 1, -s[cur]); ans += (i - cur - 1); } cur += 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...