Submission #1066706

#TimeUsernameProblemLanguageResultExecution timeMemory
1066706Gromp15Beech Tree (IOI23_beechtree)C++17
14 / 100
53 ms18000 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #include "beechtree.h" using namespace std; std::vector<int> beechtree(int n, int m, std::vector<int> p, std::vector<int> c) { vector<vector<int>> adj(n); for (int i = 1; i < n; i++) adj[p[i]].emplace_back(i); bool line = 1; for (int i = 1; i < n; i++) line &= p[i] == i-1; if (n <= 8) { vector<int> ans(n); for (int i = 0; i < n; i++) { vector<int> cur; auto dfs = [&](auto&& s, int v) -> void { cur.emplace_back(v); for (int u : adj[v]) s(s, u); }; dfs(dfs, i); sort(all(cur)); do { if (cur[0] != i) continue; map<int, int> cnt; bool ok = 1; for (int i = 1; i < sz(cur); i++) { if (p[cur[i]] != cur[cnt[c[cur[i]]]]) { ok = 0; break; } cnt[c[cur[i]]]++; } if (ok) { ans[i] = 1; break; } } while (next_permutation(all(cur))); } return ans; } if (line) { vector<int> ans(n); int col = -1; for (int i = n-1; i >= 0; i--) { if (i == n-1) ans[i] = 1, col = c[i]; else { ans[i] = 1; if (c[i] != col) break; } } return ans; } }

Compilation message (stderr)

beechtree.cpp: In function 'std::vector<int> beechtree(int, int, std::vector<int>, std::vector<int>)':
beechtree.cpp:9:27: warning: control reaches end of non-void function [-Wreturn-type]
    9 |  vector<vector<int>> adj(n);
      |                           ^
#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...
#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...