Submission #730608

#TimeUsernameProblemLanguageResultExecution timeMemory
730608danikoynovArranging Shoes (IOI19_shoes)C++14
10 / 100
0 ms212 KiB
#include "shoes.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; long long count_swaps(vector<int> s) { int n = s.size() / 2; if (n == 1) { if (s[0] > 0) return 1; return 0; } int pt0 = 0, pt1 = 0; while(pt0 < 2 * n && s[pt0] > 0) pt0 ++; while(pt1 < 2 * n && s[pt1] > 0) pt1 ++; ll ans = 0; for (int i = 0; i < 2 * n; i ++) { ///cout << i << " " << pt0 << " " << pt1 << endl; if (i % 2 == 0) { if (pt0 == i) { pt0 ++; } else { ans = ans + (ll)(pt0 - i); swap(s[pt0], s[i]); pt1 ++; } } else { if (pt1 == i) { pt1 ++; } else { pt0 ++; ans = ans + (ll)(pt1 - i); swap(s[pt1], s[i]); } } while(pt0 < 2 * n && s[pt0] > 0) pt0 ++; while(pt1 < 2 * n && s[pt1] > 0) pt1 ++; } 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...