QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#546090#2562. Fake Plastic Trees 2cwfxlhWA 5ms16536kbC++142.1kb2024-09-03 19:41:112024-09-03 19:41:11

Judging History

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

  • [2024-09-03 19:41:11]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:16536kb
  • [2024-09-03 19:41:11]
  • 提交

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(){
    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: 100
Accepted
time: 0ms
memory: 16532kb

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:

0111
0011
0000

result:

ok 3 tokens

Test #2:

score: -100
Wrong Answer
time: 5ms
memory: 16536kb

input:

100
10 9 18 50
18 0 9 8 11 11 13 16 9 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 38 50
4 10 11 13 19 6 14 14 20 14
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 26 50
6 1 12 7 1 12 20 2 0 12
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 29 50
16 13 1 17 20 15 0 3 6 7
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10...

output:

0011111111
0011111000
0111111000
0011111110
0011111110
0111111110
0011111110
0011111110
0111100000
0011111110
0111111100
0011111110
0011111111
0111110000
0011111111
0011111110
0011111110
0011111111
0111111110
0011111111
0111110000
0111111000
0111111100
0011111111
0011111111
0011111110
0011111111
001...

result:

wrong answer 1st words differ - expected: '0011000000', found: '0011111111'