QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#749552#2562. Fake Plastic Trees 2arvindr9RE 2ms3896kbC++205.7kb2024-11-15 03:43:442024-11-15 03:43:46

Judging History

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

  • [2024-11-15 03:43:46]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:3896kb
  • [2024-11-15 03:43:44]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__)
#else
#define DEBUG(...) 6
#endif
 
template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}

// Add this operator for __int128
ostream& operator << (ostream &os, __int128 x) {
    if (x < 0) {
        os << '-';
        x = -x;
    }
    if (x > 9) os << (x / 10);
    os << (int)(x % 10);
    return os;
}

template<typename T> void debug(string s, T x) {cerr << "\033[1;35m" << s << "\033[0;32m = \033[33m" << x << "\033[0m\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {for (int i=0, b=0; i<(int)s.size(); i++) if (s[i] == '(' || s[i] == '{') b++; else
if (s[i] == ')' || s[i] == '}') b--; else if (s[i] == ',' && b == 0) {cerr << "\033[1;35m" << s.substr(0, i) << "\033[0;32m = \033[33m" << x << "\033[31m | "; debug(s.substr(s.find_first_not_of(' ', i + 1)), args...); break;}}

typedef int int2;
#define int __int128
#define pi pair<int, int>
#define vi vector<int>
#define vii vector<vector<int>>
#define vpi vector<pi>
#define lep(i,l,r) for(int i=l;i<=r;++i)
#define rep(i,r,l) for(int i=r;i>=l;--i)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define f first
#define s second

long long t;

const int maxn = 1005;
const int maxk = 51;
vector<int> dp[maxn][maxk];

int2 main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> t;
    while (t--) {
        int n, k, l, r;
        {
            long long a, b, c, d;
            cin >> a >> b >> c >> d;
            n = a;
            k = b;
            l = c;
            r = d;
        }

        vector<int> a(n+1);
        lep(i,1,n) {
            long long x;
            cin >> x;
            a[i] = x;
        }
        vector<vector<int>> adj(n+1);
        lep(i,1,n-1) {
            long long u,v;
            cin >> u >> v;
            adj[u].pb(v);
            adj[v].pb(u);
        }

        vector<int> sub(n+1);
        vector<int> num_sub(n+1);

        auto dfs1 = [&](auto &self, int u, int p) -> void {
            int val = a[u];
            int num = 1;
            for (int v: adj[u]) {
                if (v != p) {
                    self(self,v,u);
                    val += sub[v];
                    num += num_sub[v];
                }
            }
            sub[u] = val;
            num_sub[u] = num;
            // assert(sub[u] >= 0);
        };

        dfs1(dfs1,1,0);

        auto simplify = [&](vector<int> a) -> vector<int> {
            if (a.empty()) return a;
            sort(a.begin(),a.end());
            a.erase(unique(a.begin(),a.end()),a.end());
            int n = a.size();
            vector<int> res = {a[0]};
            if (a.size() == 1) return res;
            lep(i,2,n-1) {
                if (a[i] <= res.back() + (r-l)) {
                    // don't push earlier element
                    continue;
                } else {
                    res.pb(a[i-1]);
                }
            }
            res.pb(a.back());
            return res;
        };

        auto dfs2 = [&](auto &self, int u, int p) -> void {
            int sz = num_sub[u];
            vector<vector<int>> curdp(min(k+2,sz+1),vector<int>());
            curdp[0].pb(0);

            for (int v: adj[u]) {
                if (v != p) {
                    self(self,v,u);
                    vector<vector<int>> nextdp(min(k+2,sz+1),vector<int>());
                    int szv = min(k,num_sub[v]);
                    lep(k1,0,sz) {
                        lep(k2,0,szv) {
                            for (int x1: curdp[k1]) {
                                for (int x2: dp[v][k2]) {
                                    if (k1 + k2 <= k+1 and x1 + x2 <= r) {
                                        nextdp[k1+k2].pb(x1+x2);
                                    }
                                }
                            }
                        }
                    }
                    lep(i,0,min(k+1,sz)) {
                        nextdp[i] = simplify(nextdp[i]);
                    }
                    swap(curdp, nextdp);
                }
            }


            // add u
            DEBUG(u);

            DEBUG(curdp);
            lep(i,0,min(k+1,sz)) {
                for (int x: curdp[i]) {
                    int next_val = x + a[u];
                    if (next_val <= r) {
                        dp[u][i].pb(next_val);
                    }
                    if (next_val >= l and next_val <= r and i < k + 1) {
                        dp[u][i+1].pb(0);
                    }
                }
                simplify(dp[u][i]);
                DEBUG(i,dp[u][i]);
            }

        };

        dfs2(dfs2,1,0);

        lep(i,1,k+1) {
            if (!dp[1][i].empty() and dp[1][i][0] == 0) {
                cout << 1;
            } else {
                cout << 0;
            }
        }
        cout << "\n";


        lep(i,1,n) {
            lep(j,0,k+1) {
                dp[i][j].clear();
            }
        }
    }

    
} 

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/

/*
4 3 1 2
1 1 1 1
1 2
2 3
3 4
*/

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3616kb

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: 0
Accepted
time: 1ms
memory: 3820kb

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
0100000000
0011111000
0110000000
0011000000
0011111100
0100000000
0010000000
0010000000
0010000000
0011000000
0111000000
0011100000
0100000000
0100000000
0100000000
0011000000
0011000000
0011111000
0011111110
001...

result:

ok 100 tokens

Test #3:

score: 0
Accepted
time: 1ms
memory: 3820kb

input:

100
10 9 23 50
13 10 9 11 14 13 11 9 14 14
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 11 50
11 9 9 9 14 7 9 12 14 5
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 27 50
14 13 9 13 9 13 9 14 14 5
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 41 50
8 10 10 13 8 6 12 7 10 5
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
1...

output:

0011000000
0011110000
0010000000
0100000000
0011110000
0100000000
0011110000
0011110000
0011100000
0100000000
0011111100
0100000000
0011100000
0011100000
0100000000
0100000000
0011111000
0011000000
0100000000
0011000000
0011111100
0011100000
0100000000
0100000000
0100000000
0011111000
0011111111
010...

result:

ok 100 tokens

Test #4:

score: 0
Accepted
time: 2ms
memory: 3600kb

input:

100
10 9 17 50
9 8 10 12 12 10 12 10 9 10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 19 50
10 9 8 10 12 12 8 11 12 10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 46 50
8 8 10 10 10 8 9 10 11 10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 9 50
9 8 11 10 11 10 10 11 11 10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 ...

output:

0011100000
0011000000
0100000000
0011111110
0011111000
0011111111
0011111000
0100000000
0011110000
0011100000
0100000000
0011100000
0011100000
0100000000
0011110000
0011110000
0011100000
0100000000
0011100000
0011111111
0100000000
0011100000
0011000000
0100000000
0011111100
0011110000
0100000000
001...

result:

ok 100 tokens

Test #5:

score: 0
Accepted
time: 2ms
memory: 3624kb

input:

100
10 9 10 50
10 11 11 10 9 9 11 9 11 10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 47 50
9 9 9 11 9 10 10 10 10 9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 49 50
9 10 9 11 11 9 11 10 10 9
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 19 50
10 9 11 11 10 11 11 9 9 11
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10...

output:

0011111100
0100000000
0100000000
0011100000
0011110000
0011111111
0011110000
0100000000
0010000000
0100000000
0011111000
0011100000
0100000000
0011110000
0011110000
0011111000
0011111111
0011110000
0011111000
0011110000
0011111100
0011100000
0011000000
0011111111
0100000000
0011111111
0100000000
001...

result:

ok 100 tokens

Test #6:

score: 0
Accepted
time: 1ms
memory: 3816kb

input:

100
10 9 50 50
50 50 50 50 50 50 50 50 50 50
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 50 50
50 50 50 50 50 50 50 50 50 50
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 50 50
50 50 50 50 50 50 50 50 50 50
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 50 50
50 50 50 50 50 50 50 50 50 50
1 2
2 3
3 4
4 5
5 6
6...

output:

0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
000...

result:

ok 100 tokens

Test #7:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

100
10 9 1793281831312430 2579712950976669
883262428445148 926941407766037 874610589009581 918671242302849 917202064660727 848094660280817 810513162735522 862049976415823 844577745576407 873085228984439
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 1890762965379103 2701769025604615
804306683243252 81402...

output:

0001000000
0001000000
0000100000
0000110000
0001111000
0000100000
0001111111
0000111100
0000111110
0000110000
0001111111
0000111000
0001100000
0001000000
0001100000
0001000000
0000111000
0001111100
0001000000
0001111110
0000110000
0000111100
0001000000
0001111111
0001100000
0001000000
0001000000
000...

result:

ok 100 tokens

Test #8:

score: 0
Accepted
time: 1ms
memory: 3604kb

input:

100
10 9 930392660078775 2806634959843587
930392660078775 905044994636391 985788965763349 912985101122684 987674992837788 921047708030944 933871032635272 924074917003015 906465081663363 976094961177209
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 1883664986961563 2834193280785472
958998107162380 924666...

output:

0000110000
0001000000
0000110000
0001110000
0001000000
0000111100
0001000000
0001000000
0001000000
0001000000
0001000000
0001100000
0001000000
0000111000
0001111000
0001000000
0001000000
0001111110
0001111110
0001000000
0001100000
0001110000
0001000000
0001110000
0000110000
0001110000
0001000000
000...

result:

ok 100 tokens

Test #9:

score: 0
Accepted
time: 2ms
memory: 3604kb

input:

100
10 9 999994984493978 2999942395429624
999994984493978 999939388770002 999967949978069 999931885129608 999990661850258 999984525481315 999963292059809 999975054238715 999981969673638 999985371517271
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 999995366940426 2999765738847089
999995366940426 9999556...

output:

0001100000
0000100000
0001000000
0000110000
0001111110
0000110000
0000111100
0001100000
0001111100
0000110000
0001100000
0000111110
0001100000
0001110000
0001111110
0000111000
0001110000
0001100000
0001100000
0000100000
0001110000
0001000000
0001000000
0001111110
0001111110
0000111110
0000100000
000...

result:

ok 100 tokens

Test #10:

score: 0
Accepted
time: 0ms
memory: 3896kb

input:

100
10 9 999999979118283 2999999819537067
999999979118283 999999975440440 999999958461371 999999979080922 999999991176682 999999985652594 999999984182267 999999928654853 999999990678448 999999900203766
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 999999951922360 2999999720940184
999999951922360 9999999...

output:

0000110000
0000111000
0001000000
0000100000
0001100000
0001100000
0001111000
0001110000
0001000000
0001000000
0000111000
0001110000
0001000000
0001111100
0001000000
0000110000
0000100000
0000110000
0001000000
0000110000
0001111111
0001111100
0001111100
0001000000
0001111100
0001110000
0000100000
000...

result:

ok 100 tokens

Test #11:

score: 0
Accepted
time: 2ms
memory: 3652kb

input:

100
10 9 999999999999480 2999999999998668
999999999999480 999999999999623 999999999999311 999999999999062 999999999999032 999999999999420 999999999999039 999999999999706 999999999999079 999999999999883
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 999999999999062 2999999999997761
999999999999062 9999999...

output:

0001110000
0000111110
0000111000
0000111100
0001110000
0000110000
0001100000
0001000000
0000111100
0000100000
0001111000
0001110000
0001111100
0001000000
0000111000
0000110000
0001000000
0001000000
0000110000
0000110000
0001110000
0001111110
0001000000
0001100000
0000111000
0001111100
0001000000
000...

result:

ok 100 tokens

Test #12:

score: 0
Accepted
time: 1ms
memory: 3668kb

input:

100
10 9 809217843509205176 1000000000000000000
819047520089857618 993247146028854493 979024090970900146 946916558454439857 809217843509205176 908857838415646655 809854521131167579 931917514552091282 890253286257158425 872828244740194237
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 810517126615250421 1...

output:

0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
000...

result:

ok 100 tokens

Test #13:

score: 0
Accepted
time: 1ms
memory: 3816kb

input:

100
10 9 990469099227929497 1000000000000000000
997087653799379867 998602320157374700 997500855340614575 998172426490578932 998173419961973183 997315871904813866 990469099227929497 991331794758268536 996329227071528815 994942302495919962
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 990138767121283623 1...

output:

0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
000...

result:

ok 100 tokens

Test #14:

score: 0
Accepted
time: 1ms
memory: 3624kb

input:

100
10 9 1000000000000000000 1000000000000000000
1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 9 100000000...

output:

0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
0000000001
000...

result:

ok 100 tokens

Test #15:

score: -100
Runtime Error

input:

1
1000 50 3 50
0 0 1 0 1 0 0 0 0 1 1 1 0 0 1 1 0 0 1 0 0 0 1 1 1 0 0 0 0 1 0 1 0 0 1 0 0 1 1 0 0 1 0 1 0 1 1 1 1 0 0 1 0 0 1 1 1 0 1 1 1 0 0 0 1 0 0 1 0 0 1 1 0 1 1 1 1 0 1 0 0 0 1 1 0 1 1 1 0 0 0 1 1 0 0 0 1 0 0 0 1 0 1 1 1 1 0 0 0 0 1 1 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1 1 1 0 1 0 1 1 0 1 1 1 1 0 0 0 1...

output:


result: