QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#69497 | #2562. Fake Plastic Trees 2 | liuhengxi | WA | 3ms | 2872kb | C++14 | 2.3kb | 2022-12-27 22:48:24 | 2022-12-27 22:48:28 |
Judging History
answer
// created: Dec/24/2022 11:51:02
#include<cstdio>
#include<cstring>
#include<vector>
#define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i)
using namespace std;
template<typename T>void readmain(T &x)
{
bool neg=false;
unsigned int c=getchar();
for(;(c^48)>9;c=getchar())if(c=='-')neg=true;
for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48);
if(neg)x=-x;
}
template<typename T>T& read(T &x){readmain(x);return x;}
template<typename T,typename ...Tr>void read(T &x,Tr&... r){readmain(x);read(r...);}
constexpr int N=1005,K=52;
long long dif;
void add(long long a[2],const long long &b)
{
if(~a[1])a[0]=min(a[0],b);
else a[0]=b;
a[1]=max(a[1],b);
}
void convolution(long long a[K][2],int n,long long b[K][2],int m,long long c[K][2])
{
int ij=0;
long long t,l;
F(i,0,n+1)if(~a[i][0])F(j,(ij=i,l=(long long)ij*dif,0),m+1)if(~b[j][0])
{
l+=dif;
t=a[i][0]+b[j][0];add(c[ij+(t>=l)],t);
t=a[i][0]+b[j][1];add(c[ij+(t>=l)],t);
t=a[i][1]+b[j][0];add(c[ij+(t>=l)],t);
t=a[i][1]+b[j][1];add(c[ij+(t>=l)],t);
++ij;
}
}
int tt,n,k,siz[N];
bool ans[K];
long long a[N],l,r,f[N][K][K][2],t[K][K][2];
vector<int> adj[N];
void dfs(int u,int fa)
{
memset(f[u],0xff,sizeof(long long)*2*K*(k+1));
f[u][0][0][0]=f[u][0][0][1]=0;
siz[u]=0;
for(int v:adj[u])if(v!=fa)
{
dfs(v,u);
memset(t,0xff,sizeof(long long)*2*K*(k+1));
F(i,0,min(siz[u],k)+1)F(j,0,min(siz[v],k-i)+1)convolution(f[u][i],i,f[v][j],j,t[i+j]);
memcpy(f[u],t,sizeof(long long)*2*K*(k+1));
a[u]+=a[v];
siz[u]+=siz[v];
}
++siz[u];
if(u)
{
for(int i=min(siz[u],k);~--i;)
{
long long aa=a[u]-(i+1)*l;
F(j,0,i+1)if(~f[u][i][j][0])
{
long long x=a[u]-f[u][i][j][1]-i*l,y=a[u]-f[u][i][j][0]-i*l;
if(y>=l&&x<=r)
{
add(f[u][i+1][aa/dif],aa);
break;
}
}
}
}
else
{
for(int i=min(siz[u],k)+1;~--i;)F(j,0,i+1)if(~f[u][i][j][0])
{
long long x=a[u]-f[u][i][j][1]-i*l,y=a[u]-f[u][i][j][0]-i*l;
if(y>=l&&x<=r)ans[i]=true;
}
}
}
int main()
{
read(tt);
while(tt--)
{
read(n,k,l,r);dif=r-l;
F(i,0,n)read(a[i]);
F(i,0,n)adj[i].clear();
F(i,0,n-1)
{
int u,v;read(u,v);--u,--v;
adj[u].emplace_back(v);
adj[v].emplace_back(u);
}
memset(ans,0,sizeof ans);
dfs(0,0);
F(i,0,k+1)putchar(48+ans[i]);
puts("");
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 2872kb
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: 3ms
memory: 2852kb
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:
0011000000 0010000000 0100000000 0010000000 0011111000 0111100000 0010000000 0010000000 0000000000 0011111000 0110000000 0011000000 0011111100 0100000000 0010000000 0010000000 0010000000 0011000000 0111000000 0011100000 0100000000 0100000000 0100000000 0011000000 0011000000 0011111000 0011111110 001...
result:
wrong answer 9th words differ - expected: '0100000000', found: '0000000000'