Submission #1305669

#TimeUsernameProblemLanguageResultExecution timeMemory
1305669ayazArranging Shoes (IOI19_shoes)C++20
Compilation error
0 ms0 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) {

  #define int long long
  vector<int> a = s;
  int n = isz(a);
  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);
  }
  if (ans != (n / 2) * (n / 2 - 1) / 2) {
    for (int i = 0; i < n; i++){
      cout << a[i] << ' ';
    }
    cout << '\n';
    exit(0);
  }
  return ans;
}

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:9:19: error: conversion from 'vector<int>' to non-scalar type 'vector<long long int>' requested
    9 |   vector<int> a = s;
      |                   ^