제출 #204341

#제출 시각아이디문제언어결과실행 시간메모리
204341ADJAArranging Shoes (IOI19_shoes)C++14
30 / 100
80 ms13432 KiB
#include "shoes.h"

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <string>

#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()

using namespace std;

int n;
vector<int> s;

long long solveSameSize() {
  set<int> stA, stB;
  for (int i = 0; i < n; i++) {
    if (s[i] < 0) {
      stA.insert(i);
    } else {
      stB.insert(i);
    }
  }

  long long result = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      int mn = *stA.begin();
      stA.erase(stA.begin());
      result += max(0, mn - i);
    } else {
      int mn = *stB.begin();
      stB.erase(stB.begin());
      result += max(0, mn - i);
    }
  }

  return result;
}

long long solveFour() {
  return 0;
}

long long solveSmall() {
  return 0;
}

long long count_swaps(std::vector<int> S) {
  s = S;
  n = sz(s);

  int sz = abs(s[0]);
  bool sameSize = true;
  for (int i = 0; i < n; i++) {
    if (abs(s[i]) != sz) {
      sameSize = false;
    }
  }
  if (sameSize) {
    return solveSameSize();
  }

  bool ok = true;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] > 0 || abs(s[i]) != abs(s[i + n / 2])) {
      ok = false;
    }
  }
  for (int i = n / 2; i < n; i++) {
    if (s[i] < 0) {
      ok = false;
    }
  }
  if (ok) {
    return solveFour();
  }

  return solveSmall();
}
#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...