QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#787144 | #9806. Growing Tree | LGyxj | TL | 0ms | 3604kb | C++20 | 1.9kb | 2024-11-27 10:03:37 | 2024-11-27 10:03:44 |
Judging History
answer
//////////////////////////
// Author: lnyxj
// Time: 2024-11-27 09:23:56
///////////////////////////
#include <bits/stdc++.h>
#define xx first
#define yy second
// #define int long long
// #define double long double
using namespace std;
const int N = 2048 + 5, mod = 998244353, inv2 = mod + 1 >> 1, inf = 0x3f3f3f3f;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int n, m;
int a[N], dep[N];
vector<int> cur[N];
bool cmp(int x, int lev) {
const int t = 1 << cur[x].size();
const int l = x << n - lev, r = (x + 1 << n - lev) - 1, mid = l + r >> 1;
for (int i = 0; i < t; ++ i) {
static bool vis[N];
for (int k = 0; k < cur[x].size(); ++ k)
if (i >> k & 1) vis[cur[x][k] << 1] = 1;
else vis[cur[x][k] << 1 | 1] = 1;
unordered_set<int> st;
function<bool(int)> dfs = [&](int x) -> bool {
if (x >= m) return true;
if (vis[x]) return true;
if (st.count(dep[x]))
return false;
st.insert(dep[x]);
return dfs(x << 1) && dfs(x << 1 | 1);
};
for (int k = 0; k < cur[x].size(); ++ k)
if (i >> k & 1) vis[cur[x][k] << 1] = 0;
else vis[cur[x][k] << 1 | 1] = 0;
if (dfs(x)) return true;
}
return false;
}
int solve(int lev, int cnt) {
if (lev == 0) return cnt - 1;
const int l = 1 << lev, r = (1 << lev + 1) - 1;
for (int i = l; i <= r; i += 2) {
for (int a : cur[i]) cur[i >> 1].push_back(a);
for (int a : cur[i + 1]) cur[i >> 1].push_back(a);
if (!cmp(i >> 1, lev - 1)) cur[i >> 1].push_back(i >> 1), -- cnt;
}
if (cnt < 0) return n + 1;
return solve(lev - 1, cnt + 1);
}
void solve() {
cin >> n;
m = 1 << n + 1;
for (int i = 2; i < m; ++ i)
cin >> a[i], cur[i].clear(), dep[i] = dep[i >> 1] + a[i];
cout << n - solve(n, 1) << '\n';
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T = 1;
cin >> T;
while (T --) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
3 2 1 2 4 3 2 1 2 1 2 3 3 2 1 2 1 2 3 3 1 1
output:
1 2 -1
result:
ok 3 number(s): "1 2 -1"
Test #2:
score: -100
Time Limit Exceeded
input:
94 5 44 65 38 61 64 94 71 53 65 10 24 36 98 74 11 4 5 46 72 34 9 24 37 32 76 29 48 88 17 14 36 4 22 6 71 53 24 61 89 79 39 57 99 61 27 85 99 46 81 75 90 25 16 13 1 87 55 81 56 78 67 2 3 83 3 74 14 45 17 22 41 62 74 25 1 56 22 7 21 73 83 99 3 91 16 53 8 10 49 29 54 81 45 10 12 68 32 9 30 11 99 85 73 ...