제출 #1305673

#제출 시각아이디문제언어결과실행 시간메모리
1305673ayazArranging Shoes (IOI19_shoes)C++20
65 / 100
1095 ms2732 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
#define isz(x) (int)x.size()
long long count_swaps(std::vector<int> s) {
  vector<int> a = s;
  #define int long long
  int n = isz(a);
  bool ok = true;
  for (int i = 0; i < n / 2; i++) {
    ok &= (a[i] + a[i + n / 2] == 0);
    ok &= (a[i] < 0);
  }
  if (ok) {
    return (n / 2) * (n / 2 - 1) / 2;
  }
  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;
}

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