Submission #251791

# Submission time Handle Problem Language Result Execution time Memory
251791 2020-07-22T10:11:33 Z tinjyu Last supper (IOI12_supper) C++14
Compilation error
0 ms 0 KB
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <iostream>
#include "advisor.h"
#include "assistant.h"

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

#define inbuf_len 1 << 16
#define outbuf_len 1 << 16
using namespace std;
void ComputeAdvice(int *C, int N, int K, int M);
void Assist(unsigned char *A, int N, int K, int R);

static int N, K, M;
static int *C;

static int R;
static unsigned char *A;

static FILE *fadvice;

static int current_request = -1;
static int *in_scaffold;
static int expect_put_back;

int GetRequest(void) {
  int req;

  if (expect_put_back) {
    fprintf(stderr, "Not putting back color when it is not on the scaffold\n");
    exit(1);
  }

  req = C[++current_request];

  if (!in_scaffold[req])
    expect_put_back = TRUE;
  else
    expect_put_back = FALSE;

  printf("R %d\n", req);
  return req;
}

void PutBack(int T) {
  int req;

  if (!expect_put_back) {
    fprintf(stderr, "Putting back a color when it is already on the scaffold\n");
    exit(1);
  }

  if (!in_scaffold[T]) {
    fprintf(stderr, "Putting back a color that is not on the scaffold\n");
    exit(1);
  }

  req = C[current_request];
  in_scaffold[req] = TRUE;
  in_scaffold[T] = FALSE;
  expect_put_back = FALSE;

  printf("P %d\n", T);
}

void WriteAdvice(unsigned char a) {
  /* Normalize a to be 0 or 1 */   

  //a = !!a;
a+='0';
  if (R < M) {
    fprintf(fadvice, "%hu ", a);
    A[R] = a;
    R++;
  } else {
    fprintf(stderr, "Advisor is providing too many bits of advice\n");
    exit(1);
  };
}

static inline void input_assert(int ok) {
  if (!ok) {
    fprintf(stderr, "Invalid input file.\n");
    exit(1);
  }
}

int main() {
  int tmp;
  int i;
tmp = scanf("%d %d %d", &N, &K, &M);
  input_assert(tmp == 3);
  C = (int*) malloc(N * sizeof(int));
  for (i = 0; i < N; i++) {
    tmp = scanf("%d", &C[i]);
    input_assert(tmp == 1);
  }
  /* Set input and output buffering */
  char *inbuf, *outbuf;
  inbuf = (char*) malloc(inbuf_len * sizeof(char));
  outbuf = (char*) malloc(outbuf_len * sizeof(char));
  tmp = setvbuf(stdin, inbuf, _IOFBF, inbuf_len);
  tmp = setvbuf(stdout, outbuf, _IOFBF, outbuf_len);

  fadvice = fopen("advice.txt", "w");

  

  A = (unsigned char*) malloc(M * sizeof(int));
  ComputeAdvice(C, N, K, M);
  fprintf(fadvice, "\n2\n");

  /* Init the scaffold */
  in_scaffold = (int*) malloc(N * sizeof(int));
  for (i = 0; i < K; i++)
    in_scaffold[i] = TRUE;
  for (i = K; i < N; i++)
    in_scaffold[i] = FALSE;
  Assist(A, N, K, R);
  printf("E\n");

  return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <iostream>
#include "advisor.h"
#include "assistant.h"

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

#define inbuf_len 1 << 16
#define outbuf_len 1 << 16
using namespace std;
void ComputeAdvice(int *C, int N, int K, int M);
void Assist(unsigned char *A, int N, int K, int R);

static int N, K, M;
static int *C;

static int R;
static unsigned char *A;

static FILE *fadvice;

static int current_request = -1;
static int *in_scaffold;
static int expect_put_back;

int GetRequest(void) {
  int req;

  if (expect_put_back) {
    fprintf(stderr, "Not putting back color when it is not on the scaffold\n");
    exit(1);
  }

  req = C[++current_request];

  if (!in_scaffold[req])
    expect_put_back = TRUE;
  else
    expect_put_back = FALSE;

  printf("R %d\n", req);
  return req;
}

void PutBack(int T) {
  int req;

  if (!expect_put_back) {
    fprintf(stderr, "Putting back a color when it is already on the scaffold\n");
    exit(1);
  }

  if (!in_scaffold[T]) {
    fprintf(stderr, "Putting back a color that is not on the scaffold\n");
    exit(1);
  }

  req = C[current_request];
  in_scaffold[req] = TRUE;
  in_scaffold[T] = FALSE;
  expect_put_back = FALSE;

  printf("P %d\n", T);
}

void WriteAdvice(unsigned char a) {
  /* Normalize a to be 0 or 1 */   

  //a = !!a;
a+='0';
  if (R < M) {
    fprintf(fadvice, "%hu ", a);
    A[R] = a;
    R++;
  } else {
    fprintf(stderr, "Advisor is providing too many bits of advice\n");
    exit(1);
  };
}

static inline void input_assert(int ok) {
  if (!ok) {
    fprintf(stderr, "Invalid input file.\n");
    exit(1);
  }
}

int main() {
  int tmp;
  int i;
tmp = scanf("%d %d %d", &N, &K, &M);
  input_assert(tmp == 3);
  C = (int*) malloc(N * sizeof(int));
  for (i = 0; i < N; i++) {
    tmp = scanf("%d", &C[i]);
    input_assert(tmp == 1);
  }
  /* Set input and output buffering */
  char *inbuf, *outbuf;
  inbuf = (char*) malloc(inbuf_len * sizeof(char));
  outbuf = (char*) malloc(outbuf_len * sizeof(char));
  tmp = setvbuf(stdin, inbuf, _IOFBF, inbuf_len);
  tmp = setvbuf(stdout, outbuf, _IOFBF, outbuf_len);

  fadvice = fopen("advice.txt", "w");

  

  A = (unsigned char*) malloc(M * sizeof(int));
  ComputeAdvice(C, N, K, M);
  fprintf(fadvice, "\n2\n");

  /* Init the scaffold */
  in_scaffold = (int*) malloc(N * sizeof(int));
  for (i = 0; i < K; i++)
    in_scaffold[i] = TRUE;
  for (i = K; i < N; i++)
    in_scaffold[i] = FALSE;
  Assist(A, N, K, R);
  printf("E\n");

  return 0;
}

Compilation message

/tmp/cc0EjgS0.o: In function `WriteAdvice(unsigned char)':
advisor.cpp:(.text+0x140): multiple definition of `WriteAdvice(unsigned char)'
/tmp/ccF5E9Qv.o:advisor_grader.cpp:(.text+0x0): first defined here
/tmp/cc0EjgS0.o: In function `main':
advisor.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccF5E9Qv.o:advisor_grader.cpp:(.text.startup+0x0): first defined here
/tmp/ccF5E9Qv.o: In function `main':
advisor_grader.cpp:(.text.startup+0xbd): undefined reference to `ComputeAdvice(int*, int, int, int)'
/tmp/cc0EjgS0.o: In function `main':
advisor.cpp:(.text.startup+0x10b): undefined reference to `ComputeAdvice(int*, int, int, int)'
advisor.cpp:(.text.startup+0x1af): undefined reference to `Assist(unsigned char*, int, int, int)'
collect2: error: ld returned 1 exit status

/tmp/ccorTVWN.o: In function `GetRequest()':
assistant.cpp:(.text+0x30): multiple definition of `GetRequest()'
/tmp/ccVBUMoh.o:assistant_grader.cpp:(.text+0x0): first defined here
/tmp/ccorTVWN.o: In function `PutBack(int)':
assistant.cpp:(.text+0xb0): multiple definition of `PutBack(int)'
/tmp/ccVBUMoh.o:assistant_grader.cpp:(.text+0xd0): first defined here
/tmp/ccorTVWN.o: In function `main':
assistant.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccVBUMoh.o:assistant_grader.cpp:(.text.startup+0x0): first defined here
/tmp/ccVBUMoh.o: In function `main':
assistant_grader.cpp:(.text.startup+0x1ed): undefined reference to `Assist(unsigned char*, int, int, int)'
/tmp/ccorTVWN.o: In function `main':
assistant.cpp:(.text.startup+0x10b): undefined reference to `ComputeAdvice(int*, int, int, int)'
assistant.cpp:(.text.startup+0x1af): undefined reference to `Assist(unsigned char*, int, int, int)'
collect2: error: ld returned 1 exit status