Submission #418916

#TimeUsernameProblemLanguageResultExecution timeMemory
418916MeGustaElArroz23Mechanical Doll (IOI18_doll)C++14
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
#include <cstdio>
#include <cstdlib>
#include "doll.h"

namespace {

constexpr int P_MAX = 20000000;
constexpr int S_MAX = 400000;

int M, N;
std::vector<int> A;

bool answered;
int S;
std::vector<int> IC, IX, IY;

int read_int() {
  int x;
  if (scanf("%d", &x) != 1) {
    fprintf(stderr, "Error while reading input\n");
    exit(1);
  }
  return x;
}

void wrong_answer(const char *MSG) {
  printf("Wrong Answer: %s\n", MSG);
  exit(0);
}

void simulate() {
  if (S > S_MAX) {
    char str[50];
    sprintf(str, "over %d switches", S_MAX);
    wrong_answer(str);
  }
  for (int i = 0; i <= M; ++i) {
    if (!(-S <= IC[i] && IC[i] <= M)) {
      wrong_answer("wrong serial number");
    }
  }
  for (int j = 1; j <= S; ++j) {
    if (!(-S <= IX[j - 1] && IX[j - 1] <= M)) {
      wrong_answer("wrong serial number");
    }
    if (!(-S <= IY[j - 1] && IY[j - 1] <= M)) {
      wrong_answer("wrong serial number");
    }
  }

  int P = 0;
  std::vector<bool> state(S + 1, false);
  int pos = IC[0];
  int k = 0;
  FILE *file_log = fopen("log.txt", "w");
  fprintf(file_log, "0\n");
  for (;;) {
    fprintf(file_log, "%d\n", pos);
    if (pos < 0) {
      if (++P > P_MAX) {
        fclose(file_log);
        char str[50];
        sprintf(str, "over %d inversions", P_MAX);
        wrong_answer(str);
      }
      state[-pos] = !state[-pos];
      pos = state[-pos] ? IX[-(1 + pos)] : IY[-(1 + pos)];
    } else {
      if (pos == 0) {
        break;
      }
      if (k >= N) {
        fclose(file_log);
        wrong_answer("wrong motion");
      }
      if (pos != A[k++]) {
        fclose(file_log);
        wrong_answer("wrong motion");
      }
      pos = IC[pos];
    }
  }
  fclose(file_log);
  if (k != N) {
    wrong_answer("wrong motion");
  }
  for (int j = 1; j <= S; ++j) {
    if (state[j]) {
      wrong_answer("state 'Y'");
    }
  }
  printf("Accepted: %d %d\n", S, P);
}  

} //namespace

void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y) {
  if (answered) {
    wrong_answer("answered not exactly once");
  }
  answered = true;
  // check if input format is correct
  if ((int)C.size() != M + 1) {
    wrong_answer("wrong array length");
  }
  if (X.size() != Y.size()) {
    wrong_answer("wrong array length");
  }
  S = X.size();
  IC = C;
  IX = X;
  IY = Y;
}

/////////////
#include<bits/stdc++.h>
#include "doll.h"

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;

#define deb(x) cerr << #x << " = " << x << ", ";
#define br cerr<<'\n';
void debv_(auto v){
  	for (int x:v) cerr << x<<", ";
 	cerr<<'\n';
}
#define debv(x) cerr<< #x<<" = ", debv_(x); 

int counter=1;
vii xy(1);
vi quedansueltos(1,0);
const int INF=1000000000;

int v2(int x){
	int sol=0;
	int ac=1;
	while (ac<x){
		sol++;
		ac*=2;
	}
	return sol;
}

int create_xy(vi v, int prof){
	//deb(counter);
	//debv(v);
	if (v.size()==1){
		if(prof==0) return v[0];
		else{
			xy.push_back(pii{v[0],quedansueltos[quedansueltos.size()-1]});
			quedansueltos.push_back(-counter);
			counter++;
			return -counter+1;
		}
	}
	xy.push_back(pii{});
	int ind=counter;
	counter++;
	vi der;
	vi izq;
	for (int i=0;i<v.size();i++){
		if (i%2==0) izq.push_back(v[i]);
		else der.push_back(v[i]);
	}
	//br;
	xy[ind]=pii{create_xy(izq,prof-1),create_xy(der,prof-1)};
	//cerr << string(4*prof,' ');
	//debv(v);
	//cerr << string(4*prof,' ');
	//deb(-ind);
	//deb(xy[ind].first);
	//deb(xy[ind].second);
	//deb(-ind);
	return -ind;
}

void create_circuit(int n, vi ciclo) {
    int m=ciclo.size();
    ciclo.push_back(INF);
    vvi conexiones(n+1);
    for (int i=0;i<m;i++) conexiones[ciclo[i]].push_back(ciclo[i+1]);
	for (int i=1;i<n+1;i++){
		if (conexiones[i].size()==0) conexiones[i].push_back(i);
	}
	//for (int i=1;i<n+1;i++) debv(conexiones[i]);
	vi salidas(n+1);
	salidas[0]=ciclo[0];
	for (int i=1;i<n+1;i++) salidas[i]=create_xy(conexiones[i],v2(conexiones[i].size()));
	//cerr<<1;
	vi switchX,switchY;
	for (int i=1;i<xy.size();i++){
		if (INF==xy[i].second) xy[i].second=quedansueltos[quedansueltos.size()-1];
	}
	for (int i=1;i<n;i++){
		if (INF==salidas[i]) salidas[i]=quedansueltos[quedansueltos.size()-1];
	}

	for (int i=1;i<xy.size();i++){
		switchX.push_back(xy[i].first);
		switchY.push_back(xy[i].second);
	}
	//debv(conexiones[1]);
	debv(salidas);
	debv(switchX);
	debv(switchY);
    answer(salidas, switchX, switchY);
}

Compilation message (stderr)

doll.cpp:130:12: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
  130 | void debv_(auto v){
      |            ^~~~
doll.cpp: In function 'int create_xy(vi, int)':
doll.cpp:168:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  168 |  for (int i=0;i<v.size();i++){
      |               ~^~~~~~~~~
doll.cpp: In function 'void create_circuit(int, vi)':
doll.cpp:198:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  198 |  for (int i=1;i<xy.size();i++){
      |               ~^~~~~~~~~~
doll.cpp:205:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  205 |  for (int i=1;i<xy.size();i++){
      |               ~^~~~~~~~~~
doll.cpp: At global scope:
doll.cpp:32:6: warning: 'void {anonymous}::simulate()' defined but not used [-Wunused-function]
   32 | void simulate() {
      |      ^~~~~~~~
doll.cpp:18:5: warning: 'int {anonymous}::read_int()' defined but not used [-Wunused-function]
   18 | int read_int() {
      |     ^~~~~~~~
/usr/bin/ld: /tmp/ccwSFe4d.o: in function `answer(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)':
grader.cpp:(.text+0x1f0): multiple definition of `answer(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'; /tmp/cc97l2Fd.o:doll.cpp:(.text+0x180): first defined here
collect2: error: ld returned 1 exit status