Submission #730326

# Submission time Handle Problem Language Result Execution time Memory
730326 2023-04-25T17:27:03 Z Andrei_Calota Speedrun (RMI21_speedrun) C++14
0 / 100
133 ms 744 KB
#include <bits/stdc++.h>
#include<speedrun.h>

using namespace std;

const int NMAX = 1e3;
const int BITS = 20, HALF = 10;
const int ROOT = 1, NONE = 0;

int par[1 + NMAX];
vector<int> tree[1 + NMAX];
int lastNode; int nextPreoder[1 + NMAX];

void DFSassign (int root, int p) {
    par[root] = p;
    nextPreoder[lastNode] = root; lastNode = root;
    for (int node : tree[root])
       if (node != p)
          DFSassign (node, root);
}

/**bool bits[50][20];
void setHint (int node, int bit, bool value) {
   bits[node][bit] = value;
}
bool getHint (int node, int bit) {
   return bits[node][bit];
}**/

void assignHints (int substask, int N, int A[], int B[]) {
   setHintLen (BITS);
   for (int i = 1; i < N; i ++) {
      tree[A[i]].push_back (B[i]);
      tree[B[i]].push_back (A[i]);
   }
   DFSassign (ROOT, NONE);
   for (int node = 1; node <= N; node ++)
      for (int bit = 0; bit < HALF; bit ++)
         if (par[node] & (1 << bit))
           setHint (node, bit + 1, true);

   for (int node = 1; node <= N; node ++)
      for (int bit = HALF; bit < BITS; bit ++)
         if (nextPreoder[node] & (1 << (bit - HALF)))
           setHint (node, bit + 1, true);
}



int getPar (int node) {
   int p = 0;
   for (int bit = 0; bit < HALF; bit ++)
      if (getHint (bit + 1) == true)
        p = p + (1 << bit);
    return p;
}
int getNextPreoder (int node) {
   int preord = 0;
   for (int bit = HALF; bit < BITS; bit ++)
      if (getHint (bit + 1) == true)
        preord = preord + (1 << (bit - HALF));
   return preord;
}

void speedrun (int subtask, int N, int start) {
   int len = getLength ();

   ///cout << start << " ";
   while (start != ROOT) {
      goTo (getPar (start));
      start = getPar (start); /// cout << start << " ";
   }


   while (getNextPreoder (start) != NONE) {
      int target = getNextPreoder (start);
      while (!goTo (target)) {
         goTo (getPar (start));
         start = getPar (start);
      }
      start = target;
   }
}

Compilation message

speedrun.cpp: In function 'void speedrun(int, int, int)':
speedrun.cpp:66:8: warning: unused variable 'len' [-Wunused-variable]
   66 |    int len = getLength ();
      |        ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 97 ms 672 KB Solution didn't visit every node
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 84 ms 672 KB Invalid node index to goTo
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 99 ms 696 KB Solution didn't visit every node
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 110 ms 704 KB Output is correct
2 Incorrect 127 ms 744 KB Solution didn't visit every node
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 133 ms 708 KB Output is correct
2 Incorrect 129 ms 712 KB Solution didn't visit every node
3 Halted 0 ms 0 KB -