Блог пользователя .31

Автор .31, история, 10 лет назад, По-русски

Всем привет!

14 июня в 19:35 MSK состоится очередной раунд Codeforces #357 для участников из второго дивизиона.

Автором всех задач являюсь я, и это мой дебютный раунд на Codeforces. Надеюсь, что задачи вам понравятся.

Хотелось бы сказать большое спасибо Глебу GlebsHP Евстропову и Данилу danilka.pro Сагунову за помощь в подготовке задач, Михаилу MikeMirzayanov Мирзаянову за замечательные системы Codeforces и Polygon, а также Демиду BLIZZARD Кучеренко за помощь с дополнительными решениями задач.

Участникам будет предложено пять задач и два часа на их решение. Разбалловка будет объявлена позднее.

UPD

Разбалловка: 500-1000-1500-2000-2500

UPD

Поздравляем победителей!

Div. 2

  1. pozhaluista
  2. Bedge
  3. jerjerisfat
  4. Huyum_nik
  5. OnlyYuju

Div. 1

  1. uwi
  2. anta
  3. kmjp
  4. ngfam_kongu
  5. BigBag

UPD

Разбор

  • Проголосовать: нравится
  • +301
  • Проголосовать: не нравится

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +18 Проголосовать: не нравится

Всем удачи, высокого рейтинга и хорошего настроения!!

»
10 лет назад, скрыть # |
 
Проголосовать: нравится -30 Проголосовать: не нравится

Good luck, high rating and good mood to everyone!!

»
10 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится -292 Проголосовать: не нравится

This contest is helpless. Because it is first of yours. Give it to a more experienced one.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится -30 Проголосовать: не нравится

If you think I will get the first rank in this contest, please vote me. If you don't think so, please vote me too!

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

Please edit your template. From previous round it says "The contest duration is 2.5 hours, it will contain 6 problems." :D

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

are we gonna see another interactive problem???

»
10 лет назад, скрыть # |
 
Проголосовать: нравится -55 Проголосовать: не нравится

Im Gay.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I enjoyed Codeforces Round #350 (Div. 2) ( 6 problems, 2.5 hours).... Will it happen again?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +25 Проголосовать: не нравится

Thanks for the contest.Excited to solve good problems.All the best everyone.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

Good luck for everybody !!

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I wish my rating change into 1700+ ^_^.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится -17 Проголосовать: не нравится

Man this is my first contest in a while. May the power of Egyptians and Indians be with me.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится -16 Проголосовать: не нравится

may allah be with us :D

»
10 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +23 Проголосовать: не нравится

The comment is hidden because of too negative feedback, click here to view it

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

Any news for those who had their rating mysteriously decreased?I was in div1 but after decrease I am in div2,how will this contest affect me?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

GOOD LUCK EVERYONE!

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Где разбалловка ?)

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

feeling great!! my first ever contest on codeforces

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

I hope greedy approach does work in C :\

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Anyone solved problem D using HLD?

  • »
    »
    10 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    My topological sort passed pretests, but I hope it won't pass systests, because this is really silly and weird solution approximately in O(N2) I guess. And, by the way, what is HLD?

  • »
    »
    10 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +31 Проголосовать: не нравится

    You didn't need to find LCA (or compare nodes depths).

    Firstly, one can prove that anyone who receives a gift must give a gift to himself. If not, the person this person received a gift from would end up giving it to the person this person is going to give a gift to, as an ancestor of an ancestor is an ancestor.

    Secondly, we can prove that there are no receivers between a receiver and its givers in the ancestry tree. If there were, this receiver in the middle would either intercept the gifts from the higher receiver's givers (being on top of the list) or become a giver to the higher receiver (which is impossible if he is a receiver, as receivers must give to themselves).

    Thirdly, we can prove that there are no gaps between receivers and givers. The case of a receiver in the middle is covered in the second step. If a giver were to be in the middle, the giver's receiver would necessarily be an ancestor of the original receiver. This would either intercept the original receiver's gifts (being on top of the list) or be intercepted by the original receiver (being below him). Therefore, as neither givers not receivers are allowed to be between a receiver and its givers, we can conclude that there are no gaps between receivers and givers, and that a receiver and its givers produce a complete tree.

    Therefore, it is sufficient to check whether each giver of a receiver's parent in the ancestry tree is either another giver (for this receiver) or the receiver and that each receiver is not in turn a giver.

    After that, a simple bottom-up (in the ancestry tree) printing of all the receivers suffices.

    I'm not totally sure if I'm correct, but I guess systests or one of you might point out a problem with my proof ;)

  • »
    »
    10 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    I ended up solving it using preorder traversal + segment tree, though I was sure there were simpler solutions.

    However, my first solution involved HLD but didn't pass pretest #5 because I didn't do DFS properly from the roots.

    Here's the corrected solution using HLD: 18478224

    • »
      »
      »
      10 лет назад, скрыть # ^ |
      Rev. 3  
      Проголосовать: нравится 0 Проголосовать: не нравится

      Mine got TLE cause it's a little bit slow(constant factor may be). My Idea was first sort the gift array based on each node's level. Then check for every node from left to right if it has an ancestor(except itself) who received a gift before. After checking I update the current receiver node.

      UPD: There were some bugs on my code and my idea was not properly correct at all.

      • »
        »
        »
        »
        10 лет назад, скрыть # ^ |
        Rev. 2  
        Проголосовать: нравится 0 Проголосовать: не нравится

        Your idea is on the right track. After the contest, I found the simple solution that I was supposed to find during contest.

        • Let Dv be the depth of the node that v will be giving gift to.
        • Then, process the nodes in reverse order (starting from the leaves) and "pushing up" values Dv as we go (we always keep the minimum one).
        • Finally, check for every receiving node (people who receive gifts) if the value we stored at it in the previous step is less than its depth. If so, there' no answer.
        • If there's an answer, we can find it by adding receiver nodes in order of descending depth.

        Check out code for more clarity: 18483927

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Welp, I'm fucked. Pupil status, here I come. :/

How to solve B and C?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

How to solve D?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Why is this wrong for D?

Check for all nodes i that none of their ancestors have a A[node] lower than A[i] in the tree, if so, print -1. Otherwise, sort A[node] according to their depth in tree in reverse order, and print them. This gets WA on #5. Why? Code: 18475103

»
10 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

Making an array unique is so hard :/ costed me 8 WAs in D

First I haven't read "distinct" in output format, and then I sorted nodes by depth and somewhy assumed that std::unique will do the job. But if e.g. 1 and 2 have same depth then 1,2,1 will not work for unique..

  • »
    »
    10 лет назад, скрыть # ^ |
    Rev. 4  
    Проголосовать: нравится +8 Проголосовать: не нравится

    You don't have to make it unique — you traverse from the leaves and once you reach the vertex, where gift[nr] == nr you add it to the end of the list — complexity is O(n) but I used set in my solution for simplicity :)

    Edit — and obviously when you go from the leaves, you just check if the relationship is ok and you add to the result once you reach an appropriate node (which gives a gift to himself).

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve div2 B i got hacked two time:(

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

For D, I think it's correct that each guy must either prefer himself or his parent. Furthermore, if a guy prefers the parent, then that parent cannot prefer his parent. So you just get the BFS order of the nodes, reverse that, process in that order, be mindful of these impossibility conditions, and add a node to the list whenever someone preferred it. Also, the initial graph is a forest, so you should run this process on each tree.

Is this correct?

  • »
    »
    10 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +3 Проголосовать: не нравится

    The guy can prefer his ancestor, and all other guys between him and that ancestor (including him) must prefer the same guy — basically every node on the path between the preferring and the preferred must prefer the same guy.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Stupid mistake with C coasted me 9 WA!!! i fell sad, and stupid :(

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Nice Problems altough some are hard but it was a nice experience couldn't manage to solve them but learned some stuff on the way .

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

problem c testcase 10?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится
  • »
    »
    10 лет назад, скрыть # ^ |
    Rev. 4  
    Проголосовать: нравится 0 Проголосовать: не нравится

    I think the vector apot is not guaranteed to be sorted because for each vertex verat you reach you push back a[verat] (if it's not already there) which can be at any level higher than or equal to verat's level.

    consider this case :

    3 2 1 2 1 3 1 1 3

    In the previous case if you reach vertex 2 before vertex 3 then vertex 1 will appear before vertex 3 in the vector apot which will give WA.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +87 Проголосовать: не нравится

One second erfaniiyan , one second. . .

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I think there will be quite a lot of fails on C due to absolute value as 10**9. Many had minimum as 0 :s I was gonna hack such solution but i locked during last few minutes....

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Anyone have tricky test for C? =)

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +44 Проголосовать: не нравится

Took me 15+ minutes to understand problem D (english version). Such description... much wow!

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can anybody explain the statement of D, please. From the statement — "Each man has at most one father". Further — "The next m lines describe family relations: the (i + 1)th line consists of pair of integers pi and qi (1 ≤ pi, qi ≤ n, pi ≠ qi) meaning that the man numbered pi is the father of the man numbered qi".In first test case we have input 3 2 and 1 2. It means the man numbered 2 has 2 fathers. I don't undestand this...

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +30 Проголосовать: не нравится

Btw, just sharing a trick with you to view submissions even when system testing is pending and viewing solutions is disabled with normal UI.

Just copy the submission id from status, or get it from click on the link showing number of submissions against the problem. e.g. anta's E submission id is 18470158.

Now open the url http://mirror.codeforces.com/contest/681/submission/18470158.

Change the submission id accordingly and have fun !!

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

Thanks for the contest guys. It would be better if the stories were not that long.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

В задаче С, могут ли числа быть отрицательными??

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

how to solve B ?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +26 Проголосовать: не нравится

Very nice sample!

»
10 лет назад, скрыть # |
 
Проголосовать: нравится -45 Проголосовать: не нравится

Does anybody have an idea of the following code that occurs memory exceeded?

include <stdio.h>

include

include

include

include <assert.h>

include

include

include

using namespace std;

typedef long long int lld;

void solve() { int N; scanf("%d", &N); vector<pair<char, int>> res;

multimap<int,bool> m;
int cnt = 0;
char buf[20]; int val;
while (N--) {
    assert(m.size() <= 100000 && res.size() <= 1000000);
    scanf("%s", buf);
    if (buf[0] != 'r') scanf("%d", &val);
    if (buf[0] == 'i') {
       m.insert(make_pair(val, cnt++));
       res.push_back(make_pair(0, val));
    }
    else if (buf[0] == 'r') {
       if (m.empty()) {
         m.insert(make_pair(0, cnt++));
         res.push_back({ 0, 0 });
       }
       auto it = m.lower_bound(val);
       m.erase(it);
       res.push_back(make_pair(2, -1));
    }
    else {
       int prv_size = m.size();
       auto it_l = m.lower_bound(val),
         it_u = m.upper_bound(val);
       m.erase(m.begin(), it_l);
       for (int i = 0; i < prv_size - m.size(); i++) {
         res.push_back(make_pair(2, -1));
       }
       it_l = m.lower_bound(val),
         it_u = m.upper_bound(val);
       if (it_l == it_u) {
         m.insert(make_pair(val, cnt++));
         res.push_back(make_pair(0, val));
       }
       auto it = m.lower_bound(val);
       m.erase(it);
       res.push_back(make_pair(1, val));
    }
}

printf("%d\n", res.size());
for (auto &r : res) {
    switch (r.first) {
    case 0:
       printf("insert %d\n", r.second);
       break;
    case 1:
       printf("getMin %d\n", r.second);
       break;
    case 2:
       printf("removeMin\n");
       break;
    }
}

} int main(void) { solve(); }

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What is up with the super strict TL on B?

My solution using 108 operations got Time limit exceeded. This is really unfair, this is expected solution, it should pass.. :/

Submission: 18459463

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
»
10 лет назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

Wow!!!!eventually,That was very good contest with increasing difficulty.Thanks for the contest.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Example input data for prob. A

Applejack 2400 2400 Fluttershy 2390 2431 Pinkie_Pie -2500 -2450

I wonder if the other pretests have the other Mane six.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

priority_queue in C gave TLE :(

»
10 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +5 Проголосовать: не нравится

I think the data for D is too weak. My submission should get a wrong answer but survived to remain correct in the final standings. I made a mistake with taking care of my dfs in the main function, exist should have been initialized as true, and later become false if one of the dfs returns false. Mine just takes the value returned by the last tree. In a test case with multiple trees with the wrong tree being in the middle, and the last tree being correct, this solution would still say that a list exists.

18470729

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +26 Проголосовать: не нравится

It is like

smurfs everywhere :'(

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

My problem C got TLEd. I was using multiset. I have seen other solutions which have passed. I strongly feel that my solution should ideally be accepted. Time limit was strict in my opinion. In the contests where feedback about problem is shown at the end of the contest and solution was well under the time in pretests, it is really tough to figure out these kind of things.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can someone tell me why my submission is getting WA on testcase 10: http://mirror.codeforces.com/contest/681/submission/18477598

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

How to solve E?

»
10 лет назад, скрыть # |
Rev. 4  
Проголосовать: нравится 0 Проголосовать: не нравится

Hi all. i'm getting wrong answer 6 in problem D and i change my code i get AC.

i don't know whats wrong with my second code!

can you help me?

my codes: 18478142 & 18478267 .

UPD: i unserstand my mistake.

thanks!

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

In my code for div2E Link
In line 43 i am calling a function subtend(point p1, point p2) which accepts 2 objects of class point , but while calling it i bymistakely typed '0' instead of typing 'o' . But it did not get a compile error at it still works perfectly fine on sample .
Any idea why?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

in problem B i didn't see the sentence " there is a triple of (non-negative) integers a, b and c " and it costs me almost 300 points!!

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

How this passed system tests?

»
10 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Nice problems. I have stuck into problem D for nearly half an hour for finding an easier way to implement it. Also, here is a slightly easier version for problem E.

»
10 лет назад, скрыть # |
Rev. 5  
Проголосовать: нравится -6 Проголосовать: не нравится

неправильно предсказывает новые звания, Эксперт -> Cпециалист, Специалист -> Эксперт, Ученик -> Новичок

Исправлено

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

How to solve C with priority_queue?

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hello all ! I am getting WA on 10 th test case in the C problem .I have not implemented priority queue as most of you have done , i have used set and map. I cannot find the bug , if any of you could i would be grateful! http://mirror.codeforces.com/contest/681/submission/18478591

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

vopros Prostite pozhaluista lqqbxt343

Who are this users? Their nicknames construct a sentence in russian. I think they should be deleted from ranklist.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится -10 Проголосовать: не нравится

How to get rid of TLE in C? What am I doing slow? Looks pretty straightforward for me :/ http://mirror.codeforces.com/contest/681/submission/18478954

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +21 Проголосовать: не нравится

Who also thought, that STL priority_queue top() return MIN value?))

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +17 Проголосовать: не нравится

Perfect problem complexity for first four problems. It happens not often for div2 contest. Thank you!

»
10 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +6 Проголосовать: не нравится

Test data for problem D is weak. I sent this solution (18480432) and it got Accepted. Then I found a bug (on my way from the leaf to the root, I only updated parents with values of their children instead of keeping the minimum along the path to have the minimum of the whole subtree). A simple test like this one breaks the solution.

4 3
4 3
3 2
2 1
4 3 4 4

The Accepted code reports there's a solution, while in fact there isn't.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hello i am newbee here. So i have a question about A tast, i gues my code runs perfect, and in testing room it has passed all pretests, but when i have sent it, it could not past second preset, can you help me please, what is wrong with it? var n = readline(); var flag = true; for(i=0;i<=n;i++){ var y = readline(); y = y.split(" "); var handle = y[0]; var before = Number(y[1]); var after = Number(y[2]); if(before >= 2400 && after >2400){ print("YES"); flag = false; break; } } if(flag === true){ print("NO"); }

  • »
    »
    10 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    I changed your for condition to: for(i=0;i<n;i++)

    Before it was: for(i=0;i<=n;i++)

    But this solution is still getting WA because of two details:

    • Your 'if' condition is partially wrong. It should be: if(before >= 2400 && after > before);

    • The output is either 'YES' or 'NO'. And you don't print a 'NO' anywhere in your program.

    Hope this helps.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

A small English suggestion: in problem A you have

"his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it"

Note that the first and second "he" refer to Anton while third "he" is some participant, I think this is confusing. For this reason I would try to avoid pronouns in statements unless there is only a single possibility for each one of them.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I think you should check the test again. With this code http://mirror.codeforces.com/contest/681/submission/18485550 and the Input: 5 4 1 2 2 3 3 4 4 5 1 1 2 3 4 I got this Output: 4 4 3 2 1 (It's wrong, I think the correct answer is -1) But this code still get Accepted.

»
10 лет назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Good Contest For me as for the first time my rating has increased

»
10 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

What can I do to optimize this solution. It gives TLE 18488801 in Div2C.

»
10 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

I am having some trouble understanding problem D:

"if there is no ancestor of a person in the list, he becomes sad and leaves the celebration without giving a gift to anyone"

But according to definition every man is his own ancestor..so person must never feel sad

Also, for sample test case 1 why is the following sequence incorrect? k=2
2
1
(we dont put 3 in the sequence)