Submission #642933

#TimeUsernameProblemLanguageResultExecution timeMemory
642933danikoynovSpeedrun (RMI21_speedrun)C++14
100 / 100
161 ms892 KiB
/** * user: koynov-b21 * fname: Daniel Iliev * lname: Koynov * task: Speedrun * score: 100.0 * date: 2021-12-16 11:34:19.470183 */ #include<bits/stdc++.h> #include "speedrun.h" using namespace std; const int maxn = 1010; vector < int > g[maxn], ch[maxn]; int deg[maxn], par[maxn], nxt[maxn]; vector < int > trav; void assignDfs(int v, int p) { trav.push_back(v); for (int i = 0; i < g[v].size(); i ++) { int u = g[v][i]; if (u == p) continue; par[u] = v; assignDfs(u, v); } } void assignHints(int subtask, int N, int A[], int B[]) { setHintLen(20); for (int i = 1; i < N; i ++) { g[A[i]].push_back(B[i]); g[B[i]].push_back(A[i]); deg[A[i]] ++; deg[B[i]] ++; } assignDfs(1, -1); for (int i = 0; i < trav.size() - 1; i ++) { nxt[trav[i]] = trav[i + 1]; } for (int i = 1; i <= N; i ++) { for (int j = 0; j < 10; j ++) { if ((par[i] & (1 << j)) > 0) setHint(i, j + 1, true); } for (int j = 0; j < 10; j ++) { if ((nxt[i] & (1 << j)) > 0) setHint(i, j + 11, true); } } } void getParent(int ver) { par[ver] = 0; for (int bit = 0; bit < 10; bit ++) if (getHint(bit + 1)) par[ver] += (1 << bit); } void speedrun(int subtask, int N, int start) { int l = getLength(); for (int i = 1; i <= N; i ++) par[i] = 0; int ver = start; while(ver != 1) { getParent(ver); goTo(par[ver]); ver = par[ver]; } int cnt = 1; while(cnt < N) { int nxtn = 0; for (int bit = 0; bit < 10; bit ++) if (getHint(bit + 11)) nxtn += (1 << bit); getParent(nxtn); while(!goTo(nxtn)) { getParent(ver); goTo(par[ver]); ver = par[ver]; } goTo(nxtn); ver = nxtn; cnt ++; } }

Compilation message (stderr)

speedrun.cpp: In function 'void assignDfs(int, int)':
speedrun.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i = 0; i < g[v].size(); i ++)
      |                     ~~^~~~~~~~~~~~~
speedrun.cpp: In function 'void assignHints(int, int, int*, int*)':
speedrun.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for (int i = 0; i < trav.size() - 1; i ++)
      |                     ~~^~~~~~~~~~~~~~~~~
speedrun.cpp: In function 'void speedrun(int, int, int)':
speedrun.cpp:76:9: warning: unused variable 'l' [-Wunused-variable]
   76 |     int l = getLength();
      |         ^
#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...