QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#865091#2562. Fake Plastic Trees 2ucup-team3659WA 0ms3712kbC++201.9kb2025-01-21 14:46:072025-01-21 14:46:07

Judging History

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

  • [2025-01-21 14:46:07]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3712kb
  • [2025-01-21 14:46:07]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,l,r;
int a[1005],sz[1005];
vector<int> e[1005];
vector<int> dp[1005][55];
vector<int> g[1005];
void dfs(int pos,int fa)
{
	sz[pos]=1;
	dp[pos][0].push_back(a[pos]);
	for(int x:e[pos])
	{
		if(x==fa)
			continue;
		dfs(x,pos);
		for(int i=0;i<=sz[pos];i++)
			g[i]=dp[pos][i],dp[pos][i].clear();
		for(int i=0;i<=k&&i<=sz[pos];i++)
			for(int j=0;i+j<=k&&j<=sz[x];j++)
				for(int vx:g[i])
					for(int vy:dp[x][j])
						dp[pos][i+j].push_back(vx+vy);
		for(int i=0;i<=k;i++)
		{
			vector<int> v;
			sort(dp[pos][i].begin(),dp[pos][i].end());
			for(int x:dp[pos][i])
			{
				if(x>r)
					return;
				while((v.size()>=2&&x-v[v.size()-2]<=r-l+1)||(v.size()>=1&&x==v[v.size()-1]))
					v.pop_back();
				v.push_back(x);
			}
			dp[pos][i]=v;
		}
		sz[pos]+=sz[x];
	}
	bool f=0;
	for(int i=0;i<=k&&i<=sz[pos];i++)
	{
		vector<int> v;
		if(f)
			v.push_back(0);
		for(int x:dp[pos][i])
		{
			if(x>r)
				return;
			while((v.size()>=2&&x-v[v.size()-2]<=r-l+1)||(v.size()>=1&&x==v[v.size()-1]))
				v.pop_back();
			v.push_back(x);
		}
		f=0;
		for(int x:v)
			if(l<=x&&x<=r)
				f=1;
		dp[pos][i]=v;
//		cout<<pos<<" "<<i<<":\n";
//		for(int x:dp[pos][i])
//			cout<<x<<" ";
//		cout<<"\n";
	}
}
void test()
{
	cin>>n>>k>>l>>r;
	k++;
	for(int i=1;i<=n;i++)
		cin>>a[i],e[i].clear();
	for(int i=1;i<n;i++)
	{
		int u,v;
		cin>>u>>v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
		for(int j=0;j<=k;j++)
			dp[i][j].clear();
	dfs(1,0);
	for(int i=1;i<=k;i++)
		if(!dp[1][i].empty()&&!dp[1][i][0])
			cout<<1;
		else
			cout<<0;
	cout<<"\n";
}
signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int i=1;i<=t;i++)
		test();
}
/*
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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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:

0000
0000
0000

result:

wrong answer 1st words differ - expected: '0111', found: '0000'