QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#812492#9806. Growing TreeeastcloudWA 1ms5616kbC++141.5kb2024-12-13 16:15:212024-12-13 16:15:22

Judging History

你现在查看的是最新测评结果

  • [2024-12-13 16:15:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5616kb
  • [2024-12-13 16:15:21]
  • 提交

answer


#include<bits/stdc++.h>

#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#define cpy(x,y,s) memcpy(x,y,sizeof(x[0])*(s))
#define mset(x,v,s) memset(x,v,sizeof(x[0])*(s))
#define all(x) begin(x),end(x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ary array
#define eb emplace_back
#define IL inline
#define For(i,j,k) for(int i=(j);i<=(k);i++)
#define Fol(i,k,j) for(int i=(k);i>=(j);i--)

using namespace std;

#define N 500005

int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9')f=(ch=='-'?-1:f),ch=getchar();
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return x*f;
}
void write(int x){
    if(x<0)x=-x,putchar('-');
    if(x/10)write(x/10);
    putchar(x%10+'0');
}

void debug(auto &&...x){
    ((cerr<<x<<' '),...);
    cerr<<'\n';
}


int a[N],buc[N];

void solve(){
    int n=read();n++;
    For(i,2,(1<<n)-1)a[i]=read(),a[i]+=a[i/2];
    int res=n-1;
    for(int len=2;len<=(1<<(n-1));len<<=1){
        for(int j=(1<<(n-1));j<(1<<n);j+=len){
            For(k,j,j+len/2-1)buc[a[k]]++;
            For(k,j+len/2,j+len-1)if(buc[a[k]])res--;
            For(k,j,j+len/2-1)buc[a[k]]=0;
        }
        if(n-1-res>len-1){res=-1;break;}
    }
    if(res<0)write(-1);
    else write(n-1-res);putchar('\n');
    For(i,2,(1<<n)-1)a[i]=0;
}

int main(){
    #ifdef EAST_CLOUD
    freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    #endif
 
    int T=read();while(T--)solve();

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5608kb

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: 1ms
memory: 5616kb

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
-1
0
0
0
1
4
1
0
2
0
2
0
-1
0
-1
0
0
-1
-1
-1
-1
-1
-1
-1
0
-1
3
-1
-1
-1
-1
2
-1
-1
0
0
4
-1
1
-1
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
4
-1
1
-1
0
0
0
0
1
0
-1
-1
-1

result:

wrong answer 1st numbers differ - expected: '2', found: '3'