Прошел четвертый этап XV Открытого Кубка по программированию. Как решать задачу D?
# | 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 |
Прошел четвертый этап XV Открытого Кубка по программированию. Как решать задачу D?
Name |
---|
for every prime number P get list of positions i, where a[i] is divisible by P,
Let's denote positions as p.
So, we need to find, (j, i) such that p[i]-p[j] is maximised and next condition is hold
* p[i] — p[j] + 1 <= 2 * (i — j + 1)
or p[i] — 2*i <= p[j] — 2*j + 1
By using interval tree, for one prime, time complexity is O(|p|log(|p|))
Overall time complexity: O(n*log^2(n))
When working with a prime P[i], I always built the segtree with the vectors related to that prime. And started to find the maximum index. It was a nice problem to solve during the contest time.
How to solve L?
Find centroids of the first tree, can be one or two centroids, try both.
Find centroids of the second tree. If there are two centroids try both.
We will try all combinations of centroids. Let's denote centroid of the first tree as v and centroid of the second tree as u.
Now, we will assume that the vertex v is the vertex u in the second tree.
We try to compare two subtrees recursively,
bool isSame(v, u);
Here, subtree u in the second tree should have one more vertex than subtree v.
Now, we will compute hashes of subtrees of children u and v, after that try to match two arrays of hashes, there should remain exactly one non-matching subtree from both tree. Check them recursively.
P.S. I may miss something. :)
Hi! Please can you tell why we cannot do that:
Get power of parent of that leaf ( x )
Sorry for my English, hope you understand me.
Shortly, your proposition is: If degree sets of both trees are equal, then you conclude that trees are also equal? If I understood correctly, this should be Counter Example:
First Tree:
1-2, 1-3, 2-4, 2-5, 3-6
Second Tree:
1-2, 1-3, 2-4, 2-5, 5-6
Be the way, how to upload a picture to Codeforces?
Yes, I suggest it. Thank you for your answer. But this part is hard for me because I cannot find some counter examples.
Anyway, thank you much.
How do you compute hashes of subtrees?
how to solve K, E, H, F ?(div2)
Can anyone share their solution for problem G?