Could not find any discussion on problems, so I am posting here.
How to solve B and L?
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Could not find any discussion on problems, so I am posting here.
How to solve B and L?
Name |
---|
B:
An interval [L,R] of 1s (0 at the L-1 and R+1) is possible if and only if, the number of fallen boxes in this interval equals R-L+1 and also there's no boxes in L-1 and R+1. So we can use a dp solution. After this observation and O(N3) dp solution it's easy to decrease complexity.
O(N3) Solution: https://ideone.com/fM5nVp
O(N2) Solution: https://ideone.com/7pZh4R
O(N * log(N)) Solution: https://ideone.com/GHDnd1
O(N) Solution: https://ideone.com/L9o6dz
L: Answer is always 2 or 3, I think it's easy to come up with a solution to calculate the number of ways after that.
Thanks a lot. In L, what is the proof that answer will always be 2 or 3?
The number of the edges is 4(n - 1) and there are only n nodes. So there must be a node with degree ≤ 3.
In L, can you please give me some hints on how to calculate the number of ways?
The solution after being aware of that the answer is 2 or 3, can be enumerate the cutting edge on a tree, and calculate which of the edges should be cut on the other tree. A trick solution is to use LCA and cal sum of subtree when using DFS. Another solution is just use dsu on tree, then u can easily calculate the answer.