Submission #977981

#TimeUsernameProblemLanguageResultExecution timeMemory
977981kilkuwuArranging Shoes (IOI19_shoes)C++17
10 / 100
1080 ms3288 KiB
#include "shoes.h"

#include <bits/stdc++.h>

long long count_swaps(std::vector<int> s) {
  int n = (int) s.size() / 2;

  long long ans = 0;
  for (int i = 0; i < n; i++) {
    int f = 2 * i; 
    // find first neg
    int fn = -1;
    for (int j = f; j < 2 * n; j++) {
      if (s[j] < 0) {
        fn = j;
        break;
      }
    }

    ans += fn - f;
    std::rotate(s.begin() + f, s.begin() + fn, s.begin() + fn + 1);

    int target = -s[f];
    for (int j = f + 1; j < 2 * n; j++) {
      if (s[j] == target) {
        fn = j;
        break;
      }
    }
    ans += fn - (f + 1);
    std::rotate(s.begin() + f + 1, s.begin() + fn, s.begin() + fn + 1);
  }

  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...