QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#546087 | #2562. Fake Plastic Trees 2 | cwfxlh | WA | 4ms | 16552kb | C++14 | 2.0kb | 2024-09-03 19:40:11 | 2024-09-03 19:40:11 |
Judging History
answer
#include<bits/stdc++.h>
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;
}
int 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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 16552kb
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: 0ms
memory: 16552kb
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'