QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1175#742346#21624. 【PR #2】背包jqh333IeihonglongyinSuccess!2024-11-13 16:27:072024-11-13 16:27:07

Details

Extra Test:

Wrong Answer
time: 2ms
memory: 5100kb

input:

1
1000 30 8900 11100
153 192 183 185 196 174 200 174 199 183 198 205 164 182 193 160 187 149 189 154 164 200 184 183 170 185 190 173 203 205 149 202 194 150 166 168 209 182 173 193 207 209 196 151 194 153 189 168 149 167 182 160 173 189 186 169 159 155 168 172 163 154 160 148 160 198 153 211 197 156...

output:

0000000000000000001000000000000

result:

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

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#742346#21624. 【PR #2】背包Ieihonglongyin97 88ms8112kbC++141.5kb2024-11-13 16:25:552024-11-13 16:28:41

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][M-1]&&p[u]-f[u][i][len-M]<=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();
	}
}