QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#766159 | #2562. Fake Plastic Trees 2 | ninjadoggy1234 | RE | 1ms | 3892kb | C++20 | 7.0kb | 2024-11-20 16:25:00 | 2024-11-20 16:25:02 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL_RUN
#include <filesystem>
#endif
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define int long long
#define FOR1(i, b) for(int i = 0; i < b; i++)
#define FOR2(i, a, b) for(int i = a; i < b; i++)
#define FOR(...) EXPAND(FOR_SELECT(__VA_ARGS__, FOR2, FOR1)(__VA_ARGS__))
#define FOR_SELECT(_1, _2, _3, NAME, ...) NAME
#define EXPAND(x) x
#define ALL(vec) vec.begin(),vec.end()
#define P(var) std::cerr << #var << ": " << var << "\n"
#define SZ(arr) (int)arr.size()
using namespace std;
template<size_t N, typename T>struct Arr :public array<T, N> { Arr() = default; Arr(const T& v) :array<T, N>{} { this->fill(v); }Arr(initializer_list<T>i) :array<T, N>{} { copy(i.begin(), i.end(), this->begin()); }template<typename...A, typename = enable_if_t<N == sizeof...(A)>>Arr(A&&...a) : array<T, N>{ static_cast<T>(a)... } {}Arr& operator=(const T& v) { this->fill(v); return*this; }Arr& operator+=(const Arr& o) { FOR(i, N)(*this)[i] += o[i]; return*this; }Arr& operator-=(const Arr& o) { FOR(i, N)(*this)[i] -= o[i]; return*this; }Arr operator+(const Arr& o)const { Arr r = *this; r += o; return r; }Arr operator-(const Arr& o)const { Arr r = *this; r -= o; return r; }friend istream& operator>>(istream& in, Arr& a) { FOR(i, N)in >> a[i]; return in; }friend ostream& operator<<(ostream& out, const Arr& a) { FOR(i, N)out << a[i] << " \n"[i == N - 1]; return out; } }; namespace std { template<size_t N, typename T>struct tuple_size<Arr<N, T>> :integral_constant<size_t, N> {}; template<size_t I, size_t N, typename T>struct tuple_element<I, Arr<N, T>> { using type = T; }; template<size_t I, size_t N, typename T>T get(const Arr<N, T>& a) { return a[I]; } };
template<int D, typename T> struct Vec : vector<Vec<D - 1, T>> { Vec() :Vec(0) {} template<typename U, typename... Args> Vec(U n = U(), Args...args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {} friend ostream& operator<<(ostream& s, const Vec& v) { for (size_t i = 0; i < v.size(); ++i)s << v[i]; return s; } void Fill(const T& x) { for (auto& v : *this)v.Fill(x); } Vec& operator+=(const Vec& o) { FOR(i, this->size())(*this)[i] += o[i]; return *this; } Vec& operator-=(const Vec& o) { FOR(i, this->size())(*this)[i] -= o[i]; return *this; } Vec operator+(const Vec& o)const { Vec r(this->size()); FOR(i, this->size())r[i] = (*this)[i] + o[i]; return r; } Vec operator-(const Vec& o)const { Vec r(this->size()); FOR(i, this->size())r[i] = (*this)[i] - o[i]; return r; } friend istream& operator>>(istream& is, Vec& v) { for (auto& e : v)is >> e; return is; } };
template<typename T> struct Vec<1, T> : vector<T> { Vec() : Vec(0) {} using vector<T>::vector; Vec(initializer_list<T> l) : vector<T>(l) {} void Fill(const T& x) { fill(this->begin(), this->end(), x); } friend ostream& operator<<(ostream& s, const Vec& v) { for (size_t i = 0; i < v.size(); ++i)s << v[i] << " \n"[i == v.size() - 1]; return s; } Vec operator+(const Vec& o)const { Vec r(this->size()); FOR(i, this->size())r[i] = (*this)[i] + o[i]; return r; } Vec operator-(const Vec& o)const { Vec r(this->size()); FOR(i, this->size())r[i] = (*this)[i] - o[i]; return r; } Vec& operator+=(const Vec& o) { FOR(i, this->size())(*this)[i] += o[i]; return *this; } Vec& operator-=(const Vec& o) { FOR(i, this->size())(*this)[i] -= o[i]; return *this; } friend istream& operator>>(istream& s, Vec& v) { for (auto& e : v)s >> e; return s; } };
template<typename Edge> struct Graph { struct OutgoingEdges { const Graph* g; int l, r; OutgoingEdges(const Graph* g, int l, int r) : g(g), l(l), r(r) {} const Edge* begin() const { return l == r ? nullptr : &g->prepared_edges[l]; } const Edge* end() const { return l == r ? nullptr : &g->prepared_edges[r]; } }; vector<Edge> prepared_edges; vector<pair<int, Edge>> edges; vector<int> start; int N; inline int size() { return N - 1; } Graph() {} Graph(int N) :N(N + 1), start(N + 2) {} void AddEdge(int from, const Edge& e) { edges.emplace_back(from, e); } void Prepare() { for (const auto& e : edges) ++start[e.first + 1]; for (int i = 1; i < N; ++i) start[i] += start[i - 1]; prepared_edges.resize(edges.size() + 1); auto counter = start; for (const auto& e : edges) prepared_edges[counter[e.first]++] = e.second; } OutgoingEdges operator[](int from) const { return (from < 0 || from + 1 >= start.size()) ? OutgoingEdges(this, 0, 0) : OutgoingEdges(this, start[from], start[from + 1]); } };
inline Graph<int> ReadGraph(int N, int M, bool undirected = true, bool one_indexed = true) { Graph<int> adj(N); FOR(i, M) { int a, b; cin >> a >> b; if (one_indexed) { a--; b--; }adj.AddEdge(a, b); if (undirected) { adj.AddEdge(b, a); } }adj.Prepare(); return adj; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
const string YN[2] = { "NO\n","YES\n" };
const int oo = 3e18;
struct Solution {
const static bool kReadTestCases = 1;
stringstream out;
void Solve(stringstream& out, const bool kNeedToClear = false, int test_case = 1) {
int N, K, L, R; cin >> N >> K >> L >> R;
Vec<1, int> arr(N); cin >> arr;
auto adj = ReadGraph(N, N - 1);
Vec<1, set<Arr<2, int>>> dp(N);
auto Add = [&](set<Arr<2, int>>& temp, int a, int b) {
Arr<2, int> e(a, b);
auto it = temp.lower_bound(e);
bool add = false;
if (it == temp.end()) {
add = true;
} else {
if (it == temp.begin()) {
add = true;
} else {
auto next = *it;
--it;
auto prev = *it;
if (prev[0] == next[0] && next[1] - prev[1] > R - L) {
add = true;
}
}
}
if (add)temp.insert(e);
};
function<void(int, int)> DFS = [&](int node, int parent) {
if (arr[node] <= R) {
dp[node].emplace(0, arr[node]);
}
for (int child : adj[node]) {
if (child == parent)continue;
DFS(child, node);
set<Arr<2, int>> temp;
for (auto a : dp[node]) {
for (auto b : dp[child]) {
if (a[1] + b[1] <= R) {
//temp.emplace(a[0] + b[0], a[1] + b[1]);
Add(temp, a[0] + b[0], a[1] + b[1]);
}
if (b[1] >= L) {
//temp.emplace(a[0] + b[0] + 1, a[1]);
Add(temp, a[0] + b[0] + 1, a[1]);
}
}
}
dp[node] = temp;
}
};
DFS(0, -1);
string ans(K + 1, '0');
for (auto a : dp[0]) {
if (a[1] >= L) {
ans[a[0]] = '1';
}
}
out << ans << endl;
}
void Precompute() {
}
stringstream& Run() {
Precompute();
out << fixed << setprecision(20);
int num_cases = 1;
if (kReadTestCases)cin >> num_cases;
for (int test_case = 1; test_case <= num_cases; test_case++) {
Solve(out, test_case < num_cases, test_case);
}
return out;
}
};
#ifdef LOCAL_RUN
const int kTestCase = 0;
#include "_LocalIO.h"
#include "_StressTester.h"
#endif
Solution solution;
int32_t main() {
#ifdef LOCAL_RUN
//StressTester::Run(__FILE__);
if (LocalIO::PerformRuns(__FILE__)) return 0;
#endif
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
auto& out = solution.Run();
cout << out.str(); cout.flush();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
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: 3656kb
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: 3644kb
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: 1ms
memory: 3652kb
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: 1ms
memory: 3820kb
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: 3760kb
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: 3656kb
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: 3648kb
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: 1ms
memory: 3656kb
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: 1ms
memory: 3624kb
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: 1ms
memory: 3476kb
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: 3884kb
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: 3892kb
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: 3580kb
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...