QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#82836 | #2562. Fake Plastic Trees 2 | iye | WA | 3ms | 4856kb | C++17 | 1.6kb | 2023-02-28 21:28:49 | 2023-02-28 21:28:50 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define ll long long
#define tt __int128_t
const int N = 1005;
int n, k, sz[N];
ll L, R, A[N];
vector<ll> f[N][55], g[55], tmp;
vector<int> e[N];
void mg(int x, int y) {
fo(i, 1, k) g[i].clear();
fo(a, 1, min(sz[x], k))
fo(b, 1, min(sz[y], k - a + 1))
for(ll u : f[x][a])
for(ll v : f[y][b]) {
if(a + b <= k && v >= L && v <= R) g[a + b].push_back(u);
if(u + v <= R) g[a + b - 1].push_back(u + v);
}
fo(i, 1, k) {
sort(g[i].begin(), g[i].end());
tmp.clear();
for(ll u : g[i]) {
while(tmp.size() >= 2) {
int id = tmp.size();
if(u - tmp[id - 2] <= R - L + 1) tmp.pop_back();
else break;
}
if(tmp.empty() || tmp.back() != u) tmp.push_back(u);
}
swap(f[x][i], tmp);
}
sz[x] += sz[y];
return;
}
void dfs(int x, int from) {
fo(i, 1, k) f[x][i].clear();
sz[x] = 1, f[x][1].push_back(A[x]);
for(int y : e[x])
if(y != from) {
dfs(y, x);
mg(x, y);
}
// fo(i, 1, k) {
// for(ll u : f[x][i]) printf("%lld ", u);
// puts("");
// }
// puts("------");
return;
}
void work() {
scanf("%d %d %lld %lld", &n, &k, &L, &R); ++k;
tt sum = 0;
fo(i, 1, n) {
scanf("%lld", &A[i]);
sum += A[i];
}
fo(i, 1, n) {
e[i].clear();
}
fo(i, 2, n) {
int u, v; scanf("%d %d", &u, &v);
e[u].push_back(v);
e[v].push_back(u);
}
dfs(1, 0);
fo(i, 1, k) {
printf("%d", f[1][i].size() > 0);
}
puts("");
return;
}
int main() {
// freopen("1.in", "r", stdin);
int T; scanf("%d", &T);
while(T--) work();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 4840kb
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: 1ms
memory: 4856kb
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 0110000000 0010000000 0011111100 0111100000 0011000000 0011000000 0100000000 0011111100 0110000000 0011000000 0011111100 0110000000 0010000000 0010000000 0011000000 0011000000 0111000000 0011100000 0100000000 0110000000 0110000000 0011000000 0011000000 0011111000 0011111110 001...
result:
wrong answer 3rd words differ - expected: '0100000000', found: '0110000000'