Submission #504875

#TimeUsernameProblemLanguageResultExecution timeMemory
504875TranGiaHuy1508Speedrun (RMI21_speedrun)C++17
0 / 100
1 ms328 KiB
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; #define pb push_back #ifndef LOCAL #include "speedrun.h" #endif #ifdef LOCAL int L, n, crr, Q; bool hint[1000][20]; int visited[1000]; int A[1000], B[1000]; void setHintLen(int l){ L = l; } void setHint(int i, int j, bool b){ hint[i][j] = b; } int getLength(){ return L; } bool getHint(int j){ return hint[crr][j]; } bool goTo(int x){ for (int i=1; i<n; i++){ if ((A[i] == crr && B[i] == x) || (A[i] == x && B[i] == crr)){ crr = x; return true; } } Q++; // if (Q > 2000) throw "Wrong Answer: False queries exceeded"; return false; } #endif void fset(int x, int pos, int val){ int y = 0; if (pos) y += 10; for (int c = 0; c < 10; c++){ setHint(x, y+c, (val >> (9 - c)) & 1); } } int fget(int pos){ int y = 0; if (pos) y += 10; int res = 0; for (int c = 0; c < 10; c++){ res = res * 2 + getHint(y+c); } return res; } vvi adj; vi dfsorder, parent; void dfs(int x, int p = -1){ dfsorder.pb(x); parent[x] = (p < 0 ? 1022 : p); for (auto k: adj[x]){ if (k - p){ dfs(k, x); } } } void assignHints(int subtask, int N, int a[], int b[]){ setHintLen(20); adj.assign(N, vi()); for (int i=1; i<N; i++){ adj[a[i] - 1].pb(b[i] - 1); adj[b[i] - 1].pb(a[i] - 1); } parent.assign(N, 1022); dfs(0); for (int i=0; i<N; i++){ fset(i+1, 0, parent[i]); } for (int i=0; i<(int)dfsorder.size()-1; i++){ fset(dfsorder[i] + 1, 1, dfsorder[i]); } } void speedrun(int subtask, int N, int start){ // getLength() = 20 int c = start; int p = fget(0); while (p < 1020){ goTo(p); c = p; p = fget(0); } // at root vi r(N, 0); int sm = 1; r[c] = 1; while (sm < N){ int val = fget(1); bool test = goTo(val); while (!test){ goTo(fget(0)); test = goTo(val); } c = val; sm -= r[c]; r[c] = 1; sm++; } } #ifdef LOCAL signed main(){ cin >> n; for (int i=1; i<n; i++){ cin >> A[i] >> B[i]; } assignHints(5, n, A, B); int q; cin >> q; for (int i=0; i<q; i++){ for (int j=0; j<n; j++) visited[j] = 0; Q = 0; int st; cin >> st; crr = st; speedrun(5, n, st); for (int k=0; k<n; k++){ // if (!visited[k]) throw "Wrong answer: Not all nodes visited"; } cout << "Success with start = " << st << "\n"; } } #endif
#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...