QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1174#742317#21624. 【PR #2】背包jqh333IeihonglongyinSuccess!2024-11-13 16:24:472024-11-13 16:24:47

Details

Extra Test:

Wrong Answer
time: 2ms
memory: 5172kb

input:

1
1000 30 8900 11100
183 184 179 179 150 181 175 191 180 185 160 202 198 198 192 163 205 177 200 193 154 182 192 158 200 158 166 156 154 163 184 164 176 176 209 196 210 181 179 195 161 203 159 176 188 160 156 199 155 161 202 157 155 206 204 168 182 153 153 197 165 182 149 180 196 196 171 189 169 206...

output:

0000000000000000001000000000000

result:

wrong answer 1st words differ - expected: '0000000000000000000000000000000', found: '0000000000000000001000000000000'

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#742317#21624. 【PR #2】背包Ieihonglongyin97 87ms8088kbC++141.5kb2024-11-13 16:21:432024-11-13 16:26:09

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;const int N=1005,M=5;
int T,n,m;ll L,R,p[N],vi[N];vector<ll>f[N][55],tmp[55];vector<int>v[N];
void dfs(int u,int fa){for(int i=0;i<=m;i++)f[u][i].clear();f[u][0].push_back(0);
	for(auto i:v[u])if(i!=fa){dfs(i,u),p[u]+=p[i];for(int j=0;j<m;j++)tmp[j].clear();
		for(int a=0;a<m;a++)for(int b=0;a+b<m;b++)
			for(auto x:f[u][a])for(auto y:f[i][b])tmp[a+b].push_back(x+y);
		for(int j=0;j<m;j++){sort(tmp[j].begin(),tmp[j].end());
			tmp[j].erase(unique(tmp[j].begin(),tmp[j].end()),tmp[j].end()),f[u][j].clear();
			for(int k=0;k<min(M,(int)tmp[j].size());k++)f[u][j].push_back(tmp[j][k]);
			for(int k=max(M,(int)tmp[j].size()-M);k<tmp[j].size();k++)f[u][j].push_back(tmp[j][k]);
		}
	}
	for(int i=m-1;~i;i--)if(!f[u][i].empty()){int len=f[u][i].size();bool fl=0,tg=0;for(auto j:f[u][i])fl|=L<=p[u]-j&&p[u]-j<=R;
		if(len>=2*M){
			for(int j=1;j<M;j++)tg|=f[u][i][j]-f[u][i][j-1]<=R-L;for(int j=1;j<M;j++)tg|=f[u][i][len-j]-f[u][i][len-j-1]<=R-L;
			fl|=tg&&L<=p[u]-f[u][i][0]&&p[u]-f[u][i][len-1]<=R;
		}if(fl)f[u][i+1].push_back(p[u]);
	}
}
int main(){//freopen("tree.in","r",stdin),freopen("tree.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>T;
	while(T--){cin>>n>>m>>L>>R,m++;for(int i=1;i<=n;i++)cin>>p[i];
		for(int x,y,i=1;i<n;i++)cin>>x>>y,v[x].push_back(y),v[y].push_back(x);dfs(1,0);
		for(int i=1;i<=m;i++)cout<<(!f[1][i].empty()&&f[1][i].back()==p[1]);cout<<"\n";
		for(int i=1;i<=n;i++)v[i].clear();
	}
}