Submission #850751

#TimeUsernameProblemLanguageResultExecution timeMemory
850751ItamarSpeedrun (RMI21_speedrun)C++14
60 / 100
3519 ms41792 KiB
#define pi pair<int,int> #include <iostream> #include <map> #include <set> #include <vector> using namespace std; #define vi vector<int> #include "speedrun.h" using namespace std; void seth(int i, pi p) { for (int j = 1; j <= 10; j++) { setHint(i, j, p.first % 2); p.first /= 2; } for (int j = 11; j <= 20; j++) { setHint(i, j, p.second % 2); p.second /= 2; } } pi get() { pi ans; int j = 1; for (int i = 1; i < 1024; i*=2) { ans.first += getHint(j) * i; j++; } for (int i = 1; i < 1024; i *= 2) { ans.second += getHint(j) * i; j++; } return ans; } void dfs(int i, vi&pad, vector<vi> fr) { for (int f : fr[i]) { if (f != pad[i]) { pad[f] = i; dfs(f,pad,fr); } } } #include <queue> void assignHints(int subtask, int N, int A[], int B[]) { /* your solution here */ setHintLen(20); if (N == 1)return; vector<vi> fr(N + 1); for (int i = 1; i < N; i++) { fr[A[i]].push_back(B[i]); fr[B[i]].push_back(A[i]); } vi pad(N + 1); vector<vi> son(N + 1); dfs(1, pad, fr); for (int i = 2; i <= N; i++) { son[pad[i]].push_back(i); } /*for (int i = 1; i <= N; i++) { if (son[i].empty())son[i].push_back(0); }*/ vi v; queue<int> q; q.push(1); while (!q.empty()) { int i = q.front(); q.pop(); v.push_back(i); for (int f : son[i]) { q.push(f); } } v.push_back(0); for (int i = 0; i < N; i++) { seth(v[i], { pad[v[i]],v[i + 1] }); }/* for (int i = 1; i <= N; i++) { for (int j = 0; j < son[i].size(); j++) { int s = son[i][j]; if (s == 0)break; if (s == son[i].back()) { seth(s, { son[s][0],i }); } else { seth(s, { son[s][0],son[i][j + 1] }); } } } seth(1, { son[1][0],0 });*/ } void walk(int a, int b, vi pad) { while (a != 1) { pi p = get(); a = p.first; goTo(p.first); } vi v={b}; while (b != 1) { v.push_back(pad[b]); b = pad[b]; } for (int i = v.size() - 2; i >= 0; i--) { goTo(v[i]); } } void speedrun(int subtask, int N, int start) { if (N == 1)return; int x = start; while (x != 1) { pi p = get(); x = p.first; goTo(p.first); } vi v = { 1 }; int it = 0; vi pad(N + 1); for (int i = 0; i < N - 1; i++) { v.push_back(get().second); while (true) { walk(x, v[it], pad); x = v[it]; if (goTo(v.back())) { x = v.back(); pad[x] = v[it]; break; } else it++; } } }
#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...