Submission #102736

#TimeUsernameProblemLanguageResultExecution timeMemory
102736MinnakhmetovAmusement Park (JOI17_amusement_park)C++14
0 / 100
546 ms190676 KiB
#include "Joi.h" #include <vector> #include <map> #include <algorithm> using namespace std; #define ll long long #define all(aaa) aaa.begin(), aaa.end() static const int N = 1e4 + 5, D = 60; static vector<int> g[N]; static int num[N]; static struct Tree { vector<int> t[D]; int id_to_node[D]; map<int, int> node_to_id; Tree() { fill(id_to_node, id_to_node + D, -1); } void addNode(int node) { for (int i = 0; i < D; i++) { if (id_to_node[i] == -1) { id_to_node[i] = node; node_to_id[node] = i; break; } } } void addEdge(int x, int y) { x = node_to_id[x]; y = node_to_id[y]; t[x].push_back(y); t[y].push_back(x); } void delNode(int id) { for (int to : t[id]) { t[to].erase(find(all(t[to]), id)); } t[id].clear(); node_to_id.erase(id_to_node[id]); id_to_node[id] = -1; } int popLeafNotEqualTo(int node) { int id = -1; for (int i = 0; i < D; i++) { if (id_to_node[i] != -1 && id_to_node[i] != node) { id = i; break; } } int deletedNode = id_to_node[id]; delNode(id); return deletedNode; } int getNodeCount() { return node_to_id.size(); } } tr[N]; static void dfs(int node, int anc, Tree &t) { num[node] = t.getNodeCount(); t.addNode(node); if (anc != -1) t.addEdge(node, anc); if (t.getNodeCount() == 60) return; for (int to : g[node]) { if (num[to] == -1) { dfs(to, node, t); if (t.getNodeCount() == 60) return; } } } static void deep(int node, int anc, Tree t) { num[node] = num[t.popLeafNotEqualTo(anc)]; t.addNode(node); t.addEdge(node, anc); tr[node] = t; for (int to : g[node]) { if (num[to] == -1) { deep(to, node, t); } } } void Joi(int n, int m, int A[], int B[], long long x, int t) { for (int i = 0; i < m; i++) { g[A[i]].push_back(B[i]); g[B[i]].push_back(A[i]); } fill(num, num + n, -1); Tree fir; dfs(0, -1, fir); for (int i = 0; i < n; i++) { if (num[i] != -1) { for (int to : g[i]) { if (num[to] == -1) { deep(to, i, fir); } } } } for(int i = 0; i < n; i++){ MessageBoard(i, (x >> num[i]) & 1); } }
#include "Ioi.h" #include <vector> #include <map> #include <algorithm> using namespace std; #define ll long long #define all(aaa) aaa.begin(), aaa.end() static const int N = 1e4 + 5, D = 60; static vector<int> g[N]; static int num[N]; struct Tree { vector<int> t[D]; int id_to_node[D]; map<int, int> node_to_id; Tree() { fill(id_to_node, id_to_node + D, -1); } void addNode(int node) { for (int i = 0; i < D; i++) { if (id_to_node[i] == -1) { id_to_node[i] = node; node_to_id[node] = i; break; } } } void addEdge(int x, int y) { x = node_to_id[x]; y = node_to_id[y]; t[x].push_back(y); t[y].push_back(x); } void delNode(int id) { for (int to : t[id]) { t[to].erase(find(all(t[to]), id)); } t[id].clear(); node_to_id.erase(id_to_node[id]); id_to_node[id] = -1; } int popLeafNotEqualTo(int node) { int id = -1; for (int i = 0; i < D; i++) { if (id_to_node[i] != -1 && id_to_node[i] != node) { id = i; break; } } int deletedNode = id_to_node[id]; delNode(id); return deletedNode; } int getNodeCount() { return node_to_id.size(); } } tr[N]; void dfs(int node, int anc, Tree &t) { num[node] = t.getNodeCount(); t.addNode(node); if (anc != -1) t.addEdge(node, anc); if (t.getNodeCount() == 60) return; for (int to : g[node]) { if (num[to] == -1) { dfs(to, node, t); if (t.getNodeCount() == 60) return; } } } void deep(int node, int anc, Tree t) { num[node] = num[t.popLeafNotEqualTo(anc)]; t.addNode(node); t.addEdge(node, anc); tr[node] = t; for (int to : g[node]) { if (num[to] == -1) { deep(to, node, t); } } } ll ans = 0; static bool used[D]; void walk(int node, int anc, Tree &t) { used[node] = 1; for (int to : t.t[node]) { if (!used[to]) { ans |= (ll)Move(t.id_to_node[to]) << num[t.id_to_node[to]]; walk(to, node, t); } } if (anc != -1) Move(anc); } long long Ioi(int n, int m, int A[], int B[], int P, int V, int T) { for (int i = 0; i < m; i++) { g[A[i]].push_back(B[i]); g[B[i]].push_back(A[i]); } fill(num, num + n, -1); Tree fir; dfs(0, -1, fir); for (int i = 0; i < n; i++) { if (num[i] != -1) tr[i] = fir; } for (int i = 0; i < n; i++) { if (num[i] != -1) { for (int to : g[i]) { if (num[to] == -1) { deep(to, i, fir); } } } } ans |= (ll)V << num[P]; walk(P, -1, tr[P]); return ans; }
#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...