제출 #564331

#제출 시각아이디문제언어결과실행 시간메모리
5643318e7즐거운 행로 (APIO20_fun)C++17
26 / 100
511 ms19896 KiB
//Challenge: Accepted #include "fun.h" #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 100005 #define pii pair<int, int> #define ff first #define ss second #define io ios_base::sync_with_stdio(0);cin.tie(0); vector<int> adj[maxn]; int tot; int dis[18][maxn], dep[maxn], anc[18][maxn], outsiz[18][maxn]; bool good[maxn]; int getsize(int u, int v, int d) { int val = 0, ma = 0; for (int i = d-1;i >= 0;i--) ma = max(ma, dis[i][u] - dis[i][v]); for (int i = d-1;i >= 0;i--) { if (dis[i][u] - dis[i][v] == ma && good[anc[i][u]]) val -= outsiz[i][u]; } return attractionsBehind(u, v) + val; } int recur[maxn]; void solve(vector<int> v, int d) { assert(d < 18); debug("solve"); pary(v.begin(), v.end()); if (v.size() == 0) return; if (v.size() == 1) { dep[v[0]] = d; return; } int root = v[0], siz = v.size(); for (int i = d - 1;i >= 0;i--) good[anc[i][v[0]]] = 0; for (int i:v) { for (int j:adj[i]) good[j] = 1; } for (int i = 1;i < siz;i++) { if (getsize(root, v[i], d) * 2 > siz) { root = v[i]; } } //debug("root", root); dep[root] = d; vector<int> con; for (int i:v) { if (i == root) continue; recur[i] = 0; dis[d][i] = hoursRequired(root, i); anc[d][i] = root; if (dis[d][i] == 1) { adj[root].push_back(i); adj[i].push_back(root); con.push_back(i); } } for (int i = 1;i < con.size();i++) { for (int j:v) { if (j != root && !recur[j]) { //debug(j, con[i], getsize(j, con[i], d)); if (hoursRequired(j, con[i]) < dis[d][j]) { recur[j] = i; } } } } vector<vector<int> > rec; for (int i = 0;i < con.size();i++) { vector<int> tmp; int p = getsize(con[i], root, d); for (int j:v) { if (j != root && recur[j] == i) { outsiz[d][j] = p; tmp.push_back(j); } } rec.push_back(tmp); } for (auto i:rec) solve(i, d+1); } bool vis[maxn]; pii dfs(int n, int pa, int d) { pii ret = {d, n}; for (int v:adj[n]) { if (v != pa && !vis[v]) { ret = max(ret, dfs(v, n, d + 1)); } } return ret; } vector<int> createFunTour(int N, int Q) { tot = N; int H = hoursRequired(0, N - 1); int A = attractionsBehind(0, N - 1); vector<int> ini, ret; for (int i = 0;i < N;i++) ini.push_back(i); solve(ini, 0); int st = max_element(dis[0], dis[0] + N) - dis[0]; for (int i = 0;i < N;i++) { vis[st] = 1; ret.push_back(st); int nxt = dfs(st, -1, 0).ss; st = nxt; } /* for (int i = 0;i < N;i++) { debug(i); pary(adj[i].begin(), adj[i].end()); } pary(ret.begin(), ret.end()); */ return ret; }

컴파일 시 표준 에러 (stderr) 메시지

fun.cpp: In function 'void solve(std::vector<int>, int)':
fun.cpp:13:20: warning: statement has no effect [-Wunused-value]
   13 | #define debug(...) 0
      |                    ^
fun.cpp:38:2: note: in expansion of macro 'debug'
   38 |  debug("solve");
      |  ^~~~~
fun.cpp:14:19: warning: statement has no effect [-Wunused-value]
   14 | #define pary(...) 0
      |                   ^
fun.cpp:39:2: note: in expansion of macro 'pary'
   39 |  pary(v.begin(), v.end());
      |  ^~~~
fun.cpp:70:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |  for (int i = 1;i < con.size();i++) {
      |                 ~~^~~~~~~~~~~~
fun.cpp:81:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |  for (int i = 0;i < con.size();i++) {
      |                 ~~^~~~~~~~~~~~
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:108:6: warning: unused variable 'H' [-Wunused-variable]
  108 |  int H = hoursRequired(0, N - 1);
      |      ^
fun.cpp:109:6: warning: unused variable 'A' [-Wunused-variable]
  109 |  int A = attractionsBehind(0, N - 1);
      |      ^
#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...