Submission #295354

#TimeUsernameProblemLanguageResultExecution timeMemory
295354tzeroArranging Shoes (IOI19_shoes)C++14
10 / 100
1 ms384 KiB
#include <iostream> #include <vector> #include <math.h> using namespace std; using ll = long long; ll count_swaps(vector<int> s) { int n = (int)s.size(); bool same_size = true; for(int i = 0; i < n; i++) { if(i > 0 && abs(s[i]) != abs(s[i - 1])) same_size = false; } if(n == 2) { if(s[0] < 0) return 0; else return 1; } else if(same_size) { ll move_left = 0, move_right = 0; int found_already = 0; for(int i = 0; i < n; i++) if(s[i] > 0) { int pos = found_already++ * 2; move_left += abs(i - pos); } found_already = 0; for(int i = 0; i < n; i++) if(s[i] > 0) { int pos = found_already++ * 2 + 1; move_right += abs(i - pos); } return min(move_left, move_right); } else { return -1; } } /* int main() { int n; scanf("%d", &n); bool same_size = true; vector<int> s(n); for(int i = 0; i < 2 * n; i++) { scanf("%d", &s[i]); if(i > 0 && abs(s[i]) != abs(s[i - 1])) same_size = false; } if(n == 1) { if(s[0] < 0) { printf("0\n"); } else { printf("1\n"); } } else if(same_size) { ll move_left = 0, move_right = 0; int found_already = 0; for(int i = 0; i < 2 * n; i++) if(s[i] > 0) { int pos = found_already++ * 2; move_left += abs(i - pos); } found_already = 0; for(int i = 0; i < 2 * n; i++) if(s[i] > 0) { int pos = found_already++ * 2 + 1; move_right += abs(i - pos); } printf("%lld\n", min(move_left, move_right)); } else { printf("%d\n", -1); } return 0; } */
#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...