Прошел четвертый этап XV Открытого Кубка по программированию. Как решать задачу D?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Прошел четвертый этап 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?