Submission #1305647

#TimeUsernameProblemLanguageResultExecution timeMemory
1305647ayazArranging Shoes (IOI19_shoes)C++20
Compilation error
0 ms0 KiB
// #include "shoes.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define isz(x) (int)x.size()

long long count_swaps(std::vector<int> s) {
  vector<int> a = s;
  int n = isz(a);
  if (n == 2) {
    return (a[0] > 0);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0 && a[i] > 0) { 
      int d = 1e9;
      for (int j = i + 1; j < n; j++) {
        if (a[j] + a[i] == 0) {
          d = j;
          break;
        }
      }
      ans += (d - i);
      for (int j = d; j > i; j--) swap(a[j], a[j - 1]);
      continue;
    }
    if (i % 2 == 1 && (a[i] < 0 || (a[i - 1] + a[i]) != 0)) {
      int d = 1e9;
      for (int j = i + 1; j < n; j++) {
        if (a[j] + a[i - 1] == 0) {
          d = j;
          break;
        }
      }
      ans += (d - i);
      for (int j = d; j > i; j--) swap(a[j], a[j - 1]);
    }
  }
  for (int i = 0; i < n; i += 2) {
    ans += (a[i] > 0);
  }
  return ans;
}


int main() {
  int n;
  cin >> n;
  vector<int> v(2 * n);

  for (int i = 0; i < 2 * n; i++) cin >> v[i];
  cout << count_swaps(v) << '\n';
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccgJRXgO.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccSEkEb5.o:shoes.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status