Submission #228061

#TimeUsernameProblemLanguageResultExecution timeMemory
228061qkxwsmAmusement Park (JOI17_amusement_park)C++14
10 / 100
39 ms3972 KiB
#include "Joi.h" #include <bits/stdc++.h> using namespace std; template<class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template<class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } #define MP make_pair #define PB push_back #define LB lower_bound #define UB upper_bound #define fi first #define se second #define SZ(x) ((int) (x).size()) #define ALL(x) (x).begin(), (x).end() #define FOR(i, a, b) for (auto i = (a); i < (b); i++) #define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--) typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; static const int MAXN = 10013; static int N, R, V = -1; static bool islong; static vi edge[MAXN]; static int dsu[MAXN]; static int depth[MAXN], parent[MAXN]; static vi ord; static int get(int u) { return (u == dsu[u] ? u : dsu[u] = get(dsu[u])); } static bool merge(int u, int v) { u = get(u); v = get(v); if (u == v) { return false; } dsu[u] = v; return true; } static void dfs(int u, int p) { for (int v : edge[u]) { if (v == p) continue; depth[v] = depth[u] + 1; parent[v] = u; dfs(v, u); } } static void dfs1(int u, int p) { ord.PB(u); for (int v : edge[u]) { if (v == p) continue; dfs1(v, u); } } void Joi(int n, int m, int e1[], int e2[], ll val, int subtask) { N = n; iota(dsu, dsu + N, 0); FOR(i, 0, m) { int u = e1[i], v = e2[i]; if (merge(u, v)) { edge[u].PB(v); edge[v].PB(u); // cerr << "edge " << u << ' ' << v << endl; } } // cerr << "ALIVE\n"; depth[0] = 0; dfs(0, N); FOR(i, 0, N) { if (depth[i] > depth[R]) { R = i; } } depth[R] = 0; dfs(R, N); FOR(i, 0, N) { if (depth[i] == 59) { V = i; } } if (V != -1) { //solve it... FOR(i, 0, N) { bool b = (val & (1ll << (depth[i] % 60))); MessageBoard(i, b); } } else { dfs1(R, N); FOR(i, 0, N) { bool b = (val & (1ll << (i % 60))); MessageBoard(ord[i], b); } } }
#include "Ioi.h" #include <bits/stdc++.h> using namespace std; template<class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template<class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } #define MP make_pair #define PB push_back #define LB lower_bound #define UB upper_bound #define fi first #define se second #define SZ(x) ((int) (x).size()) #define ALL(x) (x).begin(), (x).end() #define FOR(i, a, b) for (auto i = (a); i < (b); i++) #define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--) typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpi; typedef vector<pll> vpl; static const int MAXN = 10013; static int N, R, V; static vi edge[MAXN]; static int dsu[MAXN]; static int depth[MAXN], parent[MAXN], pos[MAXN]; static ll ans; static vi ord; static ll solved = 0; static int get(int u) { return (u == dsu[u] ? u : dsu[u] = get(dsu[u])); } static bool merge(int u, int v) { u = get(u); v = get(v); if (u == v) { return false; } dsu[u] = v; return true; } //fidn the diameter o the tree. if it's >= 60, gg. //otherwise, go to the root, and then just like take the first 60 in preorder. static void dfs(int u, int p) { for (int v : edge[u]) { if (v == p) continue; depth[v] = depth[u] + 1; parent[v] = u; dfs(v, u); } } static void dfs1(int u, int p) { pos[u] = SZ(ord); ord.PB(u); for (int v : edge[u]) { if (v == p) continue; dfs1(v, u); } } static void dfs2(int u, int p) { for (int v : edge[u]) { if (v == p) continue; // cerr << "Move " << v << endl; int va = Move(v); if (va) { ans |= (1ll << (pos[v] % 60)); } solved |= (1ll << (pos[v] % 60)); // if (solved == (1ll << 60) - 1) // { // return; // } dfs2(v, u); // if (solved == (1ll << 60) - 1) // { // return; // } // cerr << "Move " << v << " -> " << u << endl; Move(u); } } ll Ioi(int n, int m, int e1[], int e2[], int st, int va, int subtask) { N = n; iota(dsu, dsu + N, 0); FOR(i, 0, m) { int u = e1[i], v = e2[i]; if (merge(u, v)) { edge[u].PB(v); edge[v].PB(u); // cerr << "edge " << u << ' ' << v << endl; } } depth[0] = 0; dfs(0, N); FOR(i, 0, N) { if (depth[i] > depth[R]) { R = i; } } depth[R] = 0; dfs(R, N); FOR(i, 0, N) { if (depth[i] == 59) { V = i; } } // cerr << "R = " << R << " V = " << V << endl; if (V != -1) { vi path; path.PB(V); while(path.back() != R) { path.PB(parent[path.back()]); } reverse(ALL(path)); if (depth[st] >= 59) { if (va) { ans += (1ll << (depth[st] % 60)); } FOR(i, 0, 59) { va = Move(parent[st]); st = parent[st]; if (va) { ans += (1ll << (depth[st] % 60)); } } } else { while(st != R) { va = Move(parent[st]); st = parent[st]; } if (va) { ans += (1ll << (depth[st] % 60)); } FOR(i, 1, 60) { va = Move(path[i]); st = path[i]; if (va) { ans += (1ll << (depth[st] % 60)); } } } } else { dfs1(R, N); if (va) { ans |= (1ll << (pos[st] % 60)); } solved |= (1ll << (pos[st] % 60)); // cerr << "st = " << st << endl; while(st != R) { va = Move(parent[st]); // cerr << "Move " << parent[st] << endl; st = parent[st]; if (va) { ans |= (1ll << (pos[st] % 60)); } solved |= (1ll << (pos[st] % 60)); } dfs2(R, N); } return ans; }

Compilation message (stderr)

Joi.cpp:41:13: warning: 'islong' defined but not used [-Wunused-variable]
 static bool islong;
             ^~~~~~
#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...