Submission #535912

#TimeUsernameProblemLanguageResultExecution timeMemory
535912MeGustaElArroz23Speedrun (RMI21_speedrun)C++14
0 / 100
199 ms924 KiB
#include "speedrun.h" #include<bits/stdc++.h> using namespace std; #define vi vector<int> #define vvi vector<vi> #define vb vector<bool> #define pii pair<int,int> #define vii vector<pii> ////////////////////////////////////// Part 1 /** void setHintLen (int l); void setHint (int i, int j, bool b); **/ vvi conexiones; vi padre; vvi hijos; void compute_padre_hijos(int x){ for (int y:conexiones[x]){ if (y!=padre[x]){ hijos[x].push_back(y); padre[y]=x; compute_padre_hijos(y); } } } void assign_hint1(int ind, int hint){ for (int i=10;i>=1;i--){ setHint(ind+1,i,hint%2); hint/=2; } } void assign_hint2(int ind, int hint){ for (int i=20;i>=11;i--){ setHint(ind+1,i,hint%2); hint/=2; } } void assignHints(int subtask, int n, int A[], int B[]) { setHintLen(20); conexiones=vvi(n); for (int i=1;i<=n-1;i++){ conexiones[A[i]-1].push_back(B[i]-1); conexiones[B[i]-1].push_back(A[i]-1); } padre=vi(n); hijos=vvi(n); padre[0]=-1; compute_padre_hijos(0); for (int i=0;i<n;i++) sort(hijos[i].begin(),hijos[i].end()); assign_hint1(0,1001); assign_hint2(0,hijos[0][0]); for (int i=1;i<n;i++){ if (hijos[i].size()){ //ponemos padre y primer hijo //cerr << i << ": " << padre[i] << ' ' << hijos[i][0] << '\n'; assign_hint1(i,padre[i]); assign_hint2(i,hijos[i][0]); } else{ //subimos hasta que encontramos un nuevo fork a la derecha int ant=i; int ac=padre[i]; while (hijos[ac][hijos[ac].size()-1]==ant && ac!=0){ ant=ac; ac=padre[ac]; } ////cerr << i << ' ' << ac << ' ' << hijos[ac][hijos[ac].size()-1] << '\n'; if (ac==0 && hijos[ac][hijos[ac].size()-1]==ant){ //cerr<< i << ": 1023 1023" << '\n'; assign_hint1(i,1023); assign_hint2(i,1023); } else{ assign_hint1(i,ac); for (int j=0;j<hijos[ac].size();j++){ if (hijos[ac][j]==ant){ assign_hint2(i,hijos[ac][j+1]); //cerr << i << ": " << ac << ' ' << hijos[ac][j+1] << '\n'; } } } } } ////cerr << "Assignment completed!\n"; } ///////////////////////////////////// Part 2 /** int getLength (); bool getHint (int j); bool goTo(int x); **/ int get_hint1(){ int sum=0; for (int i=1;i<=10;i++){ sum*=2; sum+=getHint(i); } return sum; } int get_hint2(){ int sum=0; for (int i=11;i<=20;i++){ sum*=2; sum+=getHint(i); } return sum; } void speedrun(int subtask, int N, int ac) { ac--; if (N==1) return; //vamos al padre (1000 fallos) if (ac!=0){ vi vecinos; for (int i=0;i<N;i++){ if (goTo(i+1)){ vecinos.push_back(i); goTo(ac+1); } } if (vecinos.size()==1){ ac=vecinos[0]; goTo(ac+1); } else{ ac=get_hint1(); goTo(ac+1); } } //subimos hasta 0 while (ac!=0){ ////cerr << ac << ' '; ac=get_hint1(); goTo(ac+1); } //bajamos hasta abajo int ant; int newac=get_hint2(); while (goTo(newac+1)){ ant=ac; ac=newac; newac=get_hint2(); } int a=get_hint1(); int b=get_hint2(); //subimos hasta a, vamos a b y luego bajamos repetidamente(1000 fallos) while (a!=1023){ ////cerr << ac << ' ' << a << ' ' << b << '\n'; ////cerr << get_hint1() << ' ' << get_hint2() << '\n'; goTo(ant+1); ac=ant; while (ac!=a){ ac=get_hint1(); goTo(ac+1); } ant=a; ac=b; goTo(b+1); newac=get_hint2(); while (goTo(newac+1)){ ////cerr << ac << ' ' << newac << '\n'; ant=ac; ac=newac; newac=get_hint2(); } a=get_hint1(); b=get_hint2(); } ////cerr << "Speedrun completado!\n"; } //////////////////////////////////////////////////////////////////////////////////////

Compilation message (stderr)

speedrun.cpp: In function 'void assignHints(int, int, int*, int*)':
speedrun.cpp:92:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |                 for (int j=0;j<hijos[ac].size();j++){
      |                              ~^~~~~~~~~~~~~~~~~
speedrun.cpp: In function 'void speedrun(int, int, int)':
speedrun.cpp:208:13: warning: 'ant' may be used uninitialized in this function [-Wmaybe-uninitialized]
  208 |         goTo(ant+1);
      |         ~~~~^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...