QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#217237#6638. TreelectionCharlieVinnieWA 164ms4512kbC++171.5kb2023-10-16 17:26:232023-10-16 17:26:24

Judging History

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

  • [2023-10-16 17:26:24]
  • 评测
  • 测评结果:WA
  • 用时:164ms
  • 内存:4512kb
  • [2023-10-16 17:26:23]
  • 提交

answer

#include "bits/stdc++.h"
#ifdef DEBUG
#include "PrettyDebug.hpp"
#else
#define debug(...) [](auto...){}(__VA_ARGS__)
#endif
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
#define assume(expr) ((!!(expr))||(exit((fprintf(stderr,"Assumption Failed: %s on Line %d\n",#expr,__LINE__),-1)),false))
#define range basic_string_view
using namespace std; typedef long long ll;
void solve(){
    int n; cin>>n; vector<int> fa(n+1); For(i,2,n) cin>>fa[i];
    vector<int> siz(n+1); Rev(i,n,2) siz[fa[i]]+=siz[i]+1;
    auto check=[&](int w) { vector<int> f(n+1); Rev(i,n,2) f[fa[i]]+=max(0,f[i]-w)+1;; return f[1]<=w; };
    int w=[&](){ int l=1,r=n; while(l<r) { int mid=(l+r)>>1; if(check(mid)) r=mid; else l=mid+1; }; return l; }();
    string ans(n+1,'0'); For(i,1,n) if(siz[i]>w) ans[i]='1';
    w--; vector<int> f(n+1); Rev(i,n,2) f[fa[i]]+=max(0,f[i]-w)+1;
    assert(f[1]>0);
    if(f[1]==1){
        vector<int> g(n+1); g[1]=1; For(i,2,n) if(f[i]>w) g[i]|=g[fa[i]];
        For(i,1,n) if(siz[i]==w&&g[i]) ans[i]='1';
    }
    cout<<ans.substr(1)<<'\n';
}
signed main(){
    atexit([](){cerr<<"Time = "<<clock()<<" ms"<<endl;});
    int T; cin>>T; while(T--) solve();
    return 0;
}

// START TYPING IF YOU DON'T KNOW WHAT TO DO
// STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
// CONTINUE, NON-STOPPING, FOR CHARLIEVINNIE

// Started Coding On: October 16 Mon, 15 : 20 : 37

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3580kb

input:

2
4
1 2 3
5
1 1 2 2

output:

1100
10000

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 164ms
memory: 4512kb

input:

10
100000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...

output:

111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

wrong answer 1st lines differ - expected: '111111111111111111111111111111...0000000000000000000000000000000', found: '111111111111111111111111111111...0000000000000000000000000000000'