Submission #1301811

#TimeUsernameProblemLanguageResultExecution timeMemory
1301811nicolo_010Scales (IOI15_scales)C++20
Compilation error
0 ms0 KiB
#include "scales.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

#define MAXN 6
#define MAX_ANSWER_CALLS 1

static int realC[MAXN];
static int ind[MAXN];
static int numQueries;
static int numAnswerCalls;

static int array[300];
static int arraySize;
static int ptr;

static void readAll() {
  ptr = 0;
  arraySize = 0;
  int x;
  while (scanf("%d", &x) == 1) {
    array[arraySize++] = x;
    assert(arraySize <= 300);
  }
}

static int readInt() {
  assert(ptr < arraySize);
  int res = array[ptr++];
  return res;
}

static void initNewTest() {
  for (int i = 0; i < MAXN; i++) {
    realC[i] = readInt();
    realC[i]--;
    ind[realC[i]] = i;
  }

  numQueries = 0;
  numAnswerCalls = 0;
}

void answer(int C[]) {
  int i;

  numAnswerCalls++;
  if (numAnswerCalls > MAX_ANSWER_CALLS)
    return;

  for (i = 0; i < 6; i++)
    printf("%d ", C[i]);
  printf("%d\n", numQueries);
}

static void checkQuery(int A, int B, int C, int D) {
  if (D == -1) {
    if (A < 1 || A > 6 || B < 1 || B > 6 || C < 1 || C > 6)
      assert(0);
    if (A == B || B == C || A == C)
      assert(0);
  } else {
    if (A < 1 || A > 6 || B < 1 || B > 6 || C < 1 || C > 6 || D < 1 || D > 6)
      assert(0);
    if (A == B || A == C || A == D || B == C || B == D || C == D)
      assert(0);
  }
}

int getMedian(int A, int B, int C) {
  numQueries++;
  checkQuery(A, B, C, -1);

  A--;
  B--;
  C--;

  if (ind[B] < ind[A] && ind[A] < ind[C])
    return A + 1;

  if (ind[C] < ind[A] && ind[A] < ind[B])
    return A + 1;

  if (ind[A] < ind[B] && ind[B] < ind[C])
    return B + 1;

  if (ind[C] < ind[B] && ind[B] < ind[A])
    return B + 1;

  return C + 1;
}

int getHeaviest(int A, int B, int C) {
  numQueries++;
  checkQuery(A, B, C, -1);

  A--;
  B--;
  C--;

  if (ind[A] > ind[B] && ind[A] > ind[C])
    return A + 1;

  if (ind[B] > ind[A] && ind[B] > ind[C])
    return B + 1;

  return C + 1;
}

int getLightest(int A, int B, int C) {
  numQueries++;
  checkQuery(A, B, C, -1);

  A--;
  B--;
  C--;

  if (ind[A] < ind[B] && ind[A] < ind[C])
    return A + 1;

  if (ind[B] < ind[A] && ind[B] < ind[C])
    return B + 1;

  return C + 1;
}

int getNextLightest(int A, int B, int C, int D) {
  int allLess = 1;

  numQueries++;
  checkQuery(A, B, C, D);

  A--;
  B--;
  C--;
  D--;

  if (ind[A] > ind[D] || ind[B] > ind[D] || ind[C] > ind[D])
    allLess = 0;

  if (allLess == 1) {
    if (ind[A] < ind[B] && ind[A] < ind[C])
      return A + 1;

    if (ind[B] < ind[A] && ind[B] < ind[C])
      return B + 1;

    return C + 1;
  }

  if (ind[A] > ind[D]) {
    if ((ind[A] < ind[B] || ind[B] < ind[D]) &&
        (ind[A] < ind[C] || ind[C] < ind[D]))
      return A + 1;
  }

  if (ind[B] > ind[D]) {
    if ((ind[B] < ind[A] || ind[A] < ind[D]) &&
        (ind[B] < ind[C] || ind[C] < ind[D]))
      return B + 1;
  }

  return C + 1;
}

int main() {

  readAll();
  fclose(stdin);

  int T, i;

  T = readInt();

  init(T);

  for (i = 1; i <= T; i++) {
    initNewTest();
    orderCoins();
  }

  return 0;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccxBHpXv.o: in function `answer':
grader.c:(.text+0x0): multiple definition of `answer'; /tmp/cc57cmlE.o:scales.cpp:(.text+0x0): first defined here
/usr/bin/ld: /tmp/ccxBHpXv.o: in function `getMedian':
grader.c:(.text+0xa0): multiple definition of `getMedian'; /tmp/cc57cmlE.o:scales.cpp:(.text+0x80): first defined here
/usr/bin/ld: /tmp/ccxBHpXv.o: in function `getHeaviest':
grader.c:(.text+0x190): multiple definition of `getHeaviest'; /tmp/cc57cmlE.o:scales.cpp:(.text+0x170): first defined here
/usr/bin/ld: /tmp/ccxBHpXv.o: in function `getLightest':
grader.c:(.text+0x250): multiple definition of `getLightest'; /tmp/cc57cmlE.o:scales.cpp:(.text+0x230): first defined here
/usr/bin/ld: /tmp/ccxBHpXv.o: in function `getNextLightest':
grader.c:(.text+0x310): multiple definition of `getNextLightest'; /tmp/cc57cmlE.o:scales.cpp:(.text+0x2f0): first defined here
/usr/bin/ld: /tmp/ccxBHpXv.o: in function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'; /tmp/cc57cmlE.o:scales.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc57cmlE.o: in function `main':
scales.cpp:(.text.startup+0xc9): undefined reference to `init'
/usr/bin/ld: scales.cpp:(.text.startup+0x139): undefined reference to `orderCoins'
/usr/bin/ld: /tmp/ccxBHpXv.o: in function `main':
grader.c:(.text.startup+0x8a): undefined reference to `init'
/usr/bin/ld: grader.c:(.text.startup+0xf9): undefined reference to `orderCoins'
collect2: error: ld returned 1 exit status