QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202348#6638. Treelectionucup-team870WA 0ms3648kbC++201.6kb2023-10-05 23:10:162023-10-05 23:10:17

Judging History

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

  • [2023-10-05 23:10:17]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3648kb
  • [2023-10-05 23:10:16]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

void solve() {
    int N;
    std::cin >> N;
    
    std::vector<int> P(N), siz(N, 1);
    P[0] = -1;
    for (int i = 1; i < N; i++) {
        // std::cin >> P[i];
        P[i]=i;
        P[i]--;
    }
    
    for (int i = N - 1; i; i--) {
        siz[P[i]] += siz[i];
    }
    
    std::string ans(N, '0');
    
    int k = *std::ranges::partition_point(std::ranges::iota_view(2, N),
        [&](int x) {
            std::vector<int> dp(N);
            for (int i = N - 1; i >= 0; i--) {
                dp[i] = std::max(0, dp[i] - (x - 2));
                if (i) {
                    dp[P[i]] += dp[i] + 1;
                }
            }
            return dp[0] > 0;
        });
    if(N==1e5){
        std::cout<<k-2<<'\n'; exit(0);
    }
    for (int i = 0; i < N; i++) {
        if (siz[i] >= k) {
            ans[i] = '1';
        }
    }
    std::vector<int> dp(N);
    for (int i = N - 1; i >= 0; i--) {
        dp[i] = std::max(0, dp[i] - (k - 3));
        if (i) {
            dp[P[i]] += dp[i] + 1;
        }
    }
    std::vector<int> f(N);
    f[0] = (dp[0] == 1);
    for (int i = 1; i < N; i++) {
        f[i] = f[P[i]] && dp[i] > 0;
    }
    for (int i = 0; i < N; i++) {
        if (siz[i] == k - 1 && f[i]) {
            ans[i] = '1';
        }
    }
    std::cout << ans << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int t;
    std::cin >> t;
    
    while (t--) {
        solve();
    }
    
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3648kb

input:

2
4
1 2 3
5
1 1 2 2

output:

1100
1

result:

wrong answer 2nd lines differ - expected: '10000', found: '1'