QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#806791#9806. Growing TreeIGVAWA 2ms18220kbC++141.7kb2024-12-09 15:15:422024-12-09 15:15:42

Judging History

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

  • [2024-12-09 15:15:42]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:18220kb
  • [2024-12-09 15:15:42]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define dep(i,a,b) for(int i=(a),i##_end=(b);i>=i##_end;--i)
using namespace std;
template<class T>inline T mymin(T x,T y){return x<y?x:y;}
template<class T>inline T mymax(T x,T y){return x>y?x:y;}
template <typename T>
inline void read(T &X){
    X=0;int w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=X*10+(ch^48),ch=getchar();
    if(w) X=-X;
}
const int maxn = 4e5 + 5;
//const double pi = acos(-1.0);
//const double eps = 1e-9;
//const int mo = 1e9 + 7;
int n,m,k,q;
int a[maxn],c[maxn],d[maxn];
int ans,tmp,cnt;
int flag;
char s[maxn];
bool ok[maxn];
vector<int>vc[maxn];
void dfs(int i,int dep){
    if(dep == n) {
        vc[i/2].emplace_back(a[i]);
        return;
    }
    dfs(i * 2,dep + 1);
    dfs(i * 2 + 1,dep + 1);
    sort(vc[i].begin(),vc[i].end());
    int sz = vc[i].size();
    rep(j,0,sz - 1){
        if(j == 0 || vc[i][j] != vc[i][j - 1]){
            vc[i/2].emplace_back(vc[i][j]+a[i]);
        }else{
            c[dep]++;
        }
    }
}
void solve(){
    read(n);
    n++;
    m = (1 << n) - 1;
    rep(i,2,m){
        read(a[i]);
    }
    rep(i,0,m + 1){
        vc[i].clear();
    }
    rep(i,0,n) c[i] = 0;
    dfs(1,1);
    int ans = 0;
    rep(i,1,n - 1){
        if(c[i]) {c[i]--;ans++;}
        c[i + 1] += c[i];
    }
    if(c[n]){
        puts("-1");
        return;
    }
    printf("%d\n",ans);
}
int main(){
    //cin.tie(0)->sync_with_stdio(false);
    int T=1,cas=1;
    read(T);
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 17832kb

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: 2ms
memory: 18220kb

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
5
-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
5

result:

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