QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#546089#2562. Fake Plastic Trees 2cwfxlhWA 0ms17176kbC++142.1kb2024-09-03 19:40:412024-09-03 19:40:41

Judging History

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

  • [2024-09-03 19:40:41]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:17176kb
  • [2024-09-03 19:40:41]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int T,n,k,l,r,k1,k2,k3,k4,k5,k6,k7,k8,k9,w[5003],ans[5003];
vector<int>E[500003];
vector<int>dp[1003][53];
vector<int>ppp;
void dfs(int now,int p){
    dp[now][0].emplace_back(w[now]);
    for(auto i:E[now]){
        if(i==p)continue;
        dfs(i,now);
        for(int j=k;j>=0;j--){
            ppp=dp[now][j];
            dp[now][j].clear();
            dp[now][j].shrink_to_fit();
            for(int u=0;u+j<=k;u++){
                for(auto v1:ppp){
                    for(auto v2:dp[i][u]){
                        if(v1+v2<=r)dp[now][j+u].emplace_back(v1+v2);
                        if(j+u+1<=k)dp[now][j+u+1].emplace_back(v1);
                    }
                }
            }
        }
        for(int j=0;j<=k;j++){
            sort(dp[now][j].begin(),dp[now][j].end());
            ppp.clear();
            ppp.shrink_to_fit();
            if(dp[now][j].size()==0)continue;
            k1=dp[now][j][0];
            ppp.emplace_back(k1);
            for(int u=1;u<dp[now][j].size();u++){
                if(u+1>=dp[now][j].size()||dp[now][j][u+1]-k1+1>r-l+1){
                    k1=dp[now][j][u];
                    ppp.emplace_back(k1);
                }
            }
            swap(dp[now][j],ppp);
        }
    }
    return;
}
signed main(){
    freopen("QOJ2562.in","r",stdin);
    ios::sync_with_stdio(false);
    cin>>T;
    while(T--){
        cin>>n>>k>>l>>r;
        for(int i=1;i<=n;i++){
            E[i].clear();
            E[i].shrink_to_fit();
            for(int j=0;j<=k;j++){
                dp[i][j].clear();
                dp[i][j].shrink_to_fit();
            }
        }
        for(int i=1;i<=n;i++)cin>>w[i];
        for(int i=1;i<n;i++){
            cin>>k1>>k2;
            E[k1].emplace_back(k2);
            E[k2].emplace_back(k1);
        }
        dfs(1,0);
        for(int i=0;i<=k;i++)ans[i]=0;
        for(int i=0;i<=k;i++){
            for(auto j:dp[1][i])if(j>=l&&j<=r)ans[i]=1;
            cout<<ans[i];
        }
        cout<<'\n';
    }
    return 0;
}

詳細信息

Test #1:

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

input:

3
4 3 1 2
1 1 1 1
1 2
2 3
3 4
4 3 1 2
1 1 1 1
1 2
1 3
1 4
4 3 0 0
1 1 1 1
1 2
1 3
1 4

output:


result:

wrong answer Unexpected EOF in the participants output