Submission #620873

#TimeUsernameProblemLanguageResultExecution timeMemory
6208738e7Stations (IOI20_stations)C++17
0 / 100
826 ms668 KiB
//Challenge: Accepted #include <bits/stdc++.h> using namespace std; #ifdef zisk void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r){ while (l != r) cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif #define ll long long #define maxn 1000 #define pii pair<int, int> #define ff first #define ss second #include "stations.h" const int mul = 501; vector<int> adj[maxn]; int in[maxn], out[maxn], siz[maxn]; int tin, tout; void getsiz(int n, int par) { siz[n] = 1; for (int v:adj[n]) { if (v != par) { getsiz(v, n); siz[n] += siz[v]; } } } int getcentroid(int n, int par, int tot) { for (int v:adj[n]) { if (v != par && siz[v] * 2 > tot) { return getcentroid(v, n, tot); } } return n; } int dep[maxn]; void dfs(int n, int par, int d) { dep[n] = d; in[n] = tin++; siz[n] = 1; for (int v:adj[n]) { if (v != par) { dfs(v, n, d+1); siz[n] += siz[v]; } } out[n] = tout++; } std::vector<int> label(int n, int LIM, std::vector<int> U, std::vector<int> V) { vector<int> ret(n); for (int i = 0;i < n;i++) { adj[i].clear(); in[i] = 0, out[i] = 0; siz[i] = 0; } tin = tout = 0; for (int i = 0;i < n - 1;i++) { adj[U[i]].push_back(V[i]); adj[V[i]].push_back(U[i]); } getsiz(0, -1); int root = getcentroid(0, -1, n); dfs(root, -1, 0); for (int i = 0; i < n; i++) { if (dep[i] % 2 == 0) ret[i] = in[i] * 2 + 1; else ret[i] = out[i] * 2 + 2; } ret[root] = 0; pary(ret.begin(), ret.end()); return ret; } const int inf = 1e9; int find_next_station(int s, int t, std::vector<int> c) { int is, os, it, ot; if (s == 0) { is = 0, os = inf; int best = 0, bv = inf; t--; for (int v:c) { if (v/2 > t/2) { if (v/2 < bv) { bv = v/2; best = v; } } } return best; } else { s--; if (s % 2 == 0) { //in is = s/2; vector<int> tmp; for (int v:c) { if (v == 0) tmp.push_back(inf); else tmp.push_back(v/2); } sort(tmp.begin(), tmp.end()); if (tmp.size() == 1) os = is; else os = tmp[tmp.size()-2]+1; } else { os = s/2; vector<int> tmp; for (int v:c) { if (v == 0) tmp.push_back(-inf); else tmp.push_back(v/2); } sort(tmp.begin(), tmp.end()); if (tmp.size() == 1) is = os; else is = tmp[1]-1; } } if (t == 0) { for (int v:c) { if (v == 0) return v; } if (s%2 == 0) { return *max_element(c.begin(), c.end()); } else { return *min_element(c.begin(), c.end()); } } t--; if (is <= t/2 && t/2 <= os) { //subtree if (s%2==0) { int best = 0, bv = inf; for (int v:c) { if (v == 0) continue; v--; debug(v/2, t/2); if (v/2 > t/2) { if (v/2 < bv) { bv = v/2; best = v; } } } return best; } else { int best = 0, bv = 0; for (int v:c) { if (v == 0) continue; v--; debug(v/2, t/2); if (v/2 < t/2) { if (v/2 > bv) { bv = v/2; best = v; } } } return best; } } else { for (int v:c) { if (v == 0) return v; } if (s%2 == 0) { return *max_element(c.begin(), c.end()); } else { return *min_element(c.begin(), c.end()); } } return 0; }

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:13:19: warning: statement has no effect [-Wunused-value]
   13 | #define pary(...) 0
      |                   ^
stations.cpp:78:2: note: in expansion of macro 'pary'
   78 |  pary(ret.begin(), ret.end());
      |  ^~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:12:20: warning: statement has no effect [-Wunused-value]
   12 | #define debug(...) 0
      |                    ^
stations.cpp:140:5: note: in expansion of macro 'debug'
  140 |     debug(v/2, t/2);
      |     ^~~~~
stations.cpp:12:20: warning: statement has no effect [-Wunused-value]
   12 | #define debug(...) 0
      |                    ^
stations.cpp:154:5: note: in expansion of macro 'debug'
  154 |     debug(v/2, t/2);
      |     ^~~~~
stations.cpp:84:14: warning: unused variable 'it' [-Wunused-variable]
   84 |  int is, os, it, ot;
      |              ^~
stations.cpp:84:18: warning: unused variable 'ot' [-Wunused-variable]
   84 |  int is, os, it, ot;
      |                  ^~
#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...