QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#786870 | #9806. Growing Tree | pengpeng_fudan | WA | 3ms | 3692kb | C++23 | 1.6kb | 2024-11-27 00:21:09 | 2024-11-27 00:21:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
void solve(){
int n;
cin>>n;n++;
vector<int> f(1<<n);
for(int i=2;i<(1<<n);i++) cin>>f[i];
vector<map<int,int>> dp(1<<n);
vector<ll> leaf(1<<n);
for(int i=2;i<(1<<n);i++) {
leaf[i]=leaf[i/2]+f[i];
if(i*2>=(1<<n)) {dp[i][leaf[i]]=1;}
}
int maxn=-1;
int res=0;
auto dfs=[&](auto self,int dep,int jl)->void {
if(dep==-1) {
if(maxn==-1||maxn>res) maxn=res;
return ;
}
vector<int> op;
for(int i=(1<<dep);i<(1<<(dep+1));i++){
bool fm=false;
for(auto j:dp[i<<1]){
if(dp[i<<1|1].count(j.first)){
op.push_back(i);
fm=true;
break;
}
}
if(!fm){
for(auto j:dp[i<<1]) dp[i][j.first]=1;
for(auto j:dp[i<<1|1]) dp[i][j.first]=1;
}
}
int sz=op.size();
if(jl<sz) return ;
jl-=sz;res+=sz;
for(int j=0;j<(1<<sz);j++){
for(int k=0;k<sz;k++){
if(j<<k&1) for(auto j:dp[op[k]<<1]) dp[op[k]][j.first]=1;
else for(auto j:dp[op[k]<<1|1]) dp[op[k]][j.first]=1;
}
self(self,dep-1,jl+1);
for(auto k:op) dp[k].clear();
}
res-=sz;
};
dfs(dfs,n-2,1);
cout<<maxn<<'\n';
}
int main(){
ios::sync_with_stdio(0),cin.tie(0);
int _ =1;
cin>>_;
while(_--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
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
Wrong Answer
time: 3ms
memory: 3692kb
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 ...
output:
3 0 -1 2 0 1 -1 0 0 3 0 0 0 1 2 1 0 2 0 1 0 -1 0 -1 0 0 -1 -1 -1 -1 -1 4 -1 0 4 2 7 -1 -1 -1 1 2 5 0 0 2 -1 1 6 0 -1 2 -1 0 0 0 -1 1 -1 -1 0 0 1 1 -1 0 1 2 0 -1 0 0 1 1 -1 0 -1 0 0 0 -1 3 -1 1 -1 0 0 0 0 1 0 -1 3 3
result:
wrong answer 1st numbers differ - expected: '2', found: '3'