Submission #1069139

#TimeUsernameProblemLanguageResultExecution timeMemory
1069139Jarif_RahmanAmusement Park (JOI17_amusement_park)C++17
65 / 100
36 ms16648 KiB
#include "Joi.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; namespace { const int N = 10000; const int k = 60; int n, m; vector<int> graph[N]; vector<int> tree[N]; bitset<N> bl; int in[N], out[N]; int msg[N]; vector<int> nodes[N]; int _p = 0; void spanning_tree(int nd, int ss){ if(bl[nd]) return; bl[nd] = 1; if(ss != -1) tree[ss].push_back(nd); in[nd] = _p++; for(int x: graph[nd]) spanning_tree(x, nd); out[nd] = _p; } void create_initial_group(int nd){ if(nodes[0].size() == k) return; nodes[0].push_back(nd); for(int x: tree[nd]) create_initial_group(x); } bool contains(int x, int y){ return in[x] <= in[y] && out[x] >= out[y]; } void dfs(int nd, int ss){ if(!nodes[nd].empty()){ for(int x: tree[nd]) dfs(x, nd); return; } nodes[nd] = nodes[ss]; nodes[nd].push_back(nd); sort(nodes[nd].begin(), nodes[nd].end(), [&](int a, int b){ return in[a] < in[b]; }); int rem = -1; bool ok = contains(nodes[nd][0], nodes[nd][1]); for(int x: nodes[nd]){ if(x == nodes[nd][0] || x == nodes[nd][1]) continue; ok&=contains(nodes[nd][1], x); } if(ok) rem = nodes[nd][0]; else{ for(int x: nodes[nd]) if(x != nd){ bool ok = 1; for(int y: nodes[nd]) if(y != x) ok&=!contains(x, y); if(ok){ rem = x; break; } } } msg[nd] = msg[rem]; nodes[nd].erase(find(nodes[nd].begin(), nodes[nd].end(), rem)); for(int x: tree[nd]) dfs(x, nd); } } void Joi(int _n, int _m, int A[], int B[], ll X, int T){ n = _n, m = _m; for(int i = 0; i < m; i++){ graph[A[i]].push_back(B[i]); graph[B[i]].push_back(A[i]); } spanning_tree(0, -1); create_initial_group(0); for(int x: nodes[0]) if(x) nodes[x] = nodes[0]; for(int i = 0; i < k; i++) msg[nodes[0][i]] = i; dfs(0, -1); vector<int> bin; for(int i = 0; i < k; i++){ bin.push_back(X%2); X/=2; } for(int i = 0; i < n; i++) MessageBoard(i, bin[msg[i]]); }
#include "Ioi.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; namespace { const int N = 10000; const int k = 60; int n, m; vector<int> graph[N]; vector<int> tree[N]; bitset<N> bl; int in[N], out[N]; int msg[N]; vector<int> nodes[N]; int _p = 0; void spanning_tree(int nd, int ss){ if(bl[nd]) return; bl[nd] = 1; if(ss != -1) tree[ss].push_back(nd); in[nd] = _p++; for(int x: graph[nd]) spanning_tree(x, nd); out[nd] = _p; } void create_initial_group(int nd){ if(nodes[0].size() == k) return; nodes[0].push_back(nd); for(int x: tree[nd]) create_initial_group(x); } bool contains(int x, int y){ return in[x] <= in[y] && out[x] >= out[y]; } void dfs(int nd, int ss){ if(!nodes[nd].empty()){ for(int x: tree[nd]) dfs(x, nd); return; } nodes[nd] = nodes[ss]; nodes[nd].push_back(nd); sort(nodes[nd].begin(), nodes[nd].end(), [&](int a, int b){ return in[a] < in[b]; }); int rem = -1; bool ok = contains(nodes[nd][0], nodes[nd][1]); for(int x: nodes[nd]){ if(x == nodes[nd][0] || x == nodes[nd][1]) continue; ok&=contains(nodes[nd][1], x); } if(ok) rem = nodes[nd][0]; else{ for(int x: nodes[nd]) if(x != nd){ bool ok = 1; for(int y: nodes[nd]) if(y != x) ok&=!contains(x, y); if(ok){ rem = x; break; } } } msg[nd] = msg[rem]; nodes[nd].erase(find(nodes[nd].begin(), nodes[nd].end(), rem)); for(int x: tree[nd]) dfs(x, nd); } vector<int> bin(k); vector<int> tree2[N]; void dfs2(int nd, int ss){ for(int x: tree2[nd]) if(x != ss){ bin[msg[x]] = Move(x); dfs2(x, nd); Move(nd); } } } ll Ioi(int _n, int _m, int A[], int B[], int p, int v, int T){ n = _n, m = _m; for(int i = 0; i < m; i++){ graph[A[i]].push_back(B[i]); graph[B[i]].push_back(A[i]); } spanning_tree(0, -1); create_initial_group(0); for(int x: nodes[0]) if(x) nodes[x] = nodes[0]; for(int i = 0; i < k; i++) msg[nodes[0][i]] = i; dfs(0, -1); vector<bool> in_subtree(n, 0); for(int x: nodes[p]) in_subtree[x] = 1; for(int i = 0; i < m; i++) if(in_subtree[A[i]] && in_subtree[B[i]]){ tree2[A[i]].push_back(B[i]); tree2[B[i]].push_back(A[i]); } bin[msg[p]] = v; dfs2(p, -1); ll X = 0; for(int i = 0; i < k; i++) if(bin[i]) X+=(1LL<<i); return X; }
#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...