Submission #411383

#TimeUsernameProblemLanguageResultExecution timeMemory
411383ollelArranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include <iostream>
using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

ll ans = 0;
int n;
vi shoes;

int f(int x, int m) {
  return (x > 0) ? x : m - 1 + x;
}

void rem() {
  int pairs = n/2;
  rep(pair, 0, pairs) {

    vi dist(pairs, 0);
    rep(i,0,n) dist[shoes[i]] += i;
    int bd = 1e9, p;
    rep(i, 0, pairs) {
      if (dist[i] < bd) {bd = dist[i]; p = i;}
    }

    ans += bd - 1;
    rep(i, 0, n-1) if (shoes[i] == p) swap(shoes[i], shoes[i + 1]);
    rep(i, 0, n-1) if (shoes[i] == p) swap(shoes[i], shoes[i + 1]);

  }
}

int main()
{
  cin >> n; shoes.resize(n); rep(i,0,n) cin >> shoes[i];
  rep(i,0,n) shoes[i] = -shoes[i];

  vvi exists(2*n + 5);
  rep(i,0,n) exists[f(shoes[i], 2*n+5)].pb(i);
  int real = 0;

  rep(i,1,n+1) {
    rep(j, 0, exists[i].size()) {
      int a = exists[i][j], b = exists[f(-i, 2*n+5)][j];
      if (a > b) ans++;
      shoes[a] = shoes[b] = real;
      real++;
    }
  }
  rem();
  cout << ans << endl;
}

Compilation message (stderr)

shoes.cpp: In function 'int main()':
shoes.cpp:5:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(i,a,b) for(int i = a; i < b; i++)
......
   48 |     rep(j, 0, exists[i].size()) {
      |         ~~~~~~~~~~~~~~~~~~~~~~       
shoes.cpp:48:5: note: in expansion of macro 'rep'
   48 |     rep(j, 0, exists[i].size()) {
      |     ^~~
/usr/bin/ld: /tmp/ccqfTHKu.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccmDBWvs.o:shoes.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccqfTHKu.o: in function `main':
grader.cpp:(.text.startup+0x2a8): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status