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

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

Скоро 8 июня, в 19:30 состоится очередной Codeforces Round для участников из второго дивизиона. Участники из первого дивизиона могут поучаствовать вне конкурса.

Задачи были подготовлены группой авторов в составе: Гриднев Виталий (gridnevvvit), и Данил Сагунов (danilka.pro). Традиционно большое спасибо Gerald за помощь в подготовке в раунда, Delinur за переводы на английский и MikeMirzayanov за системы Codeforces и Polygon.

Распределение баллов по задачам будет таким 500 — 1000 — 1500 — 2000 — 2500.

Соревнование закончено, поздравляем победителей!

  1. kuangbin10
  2. ToumaKazusa
  3. qiaoranpenxiang
  4. rotoZOOM
  5. umczca195

Разбор задач можно найти здесь

Удачи!

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

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

Hope this round to be a bridge to be a div1 contestant for the first time , just hope

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

Good luck with preparing your second contest , Keep going for more =)

and I hope that the problems and the editorial will be reach with new and useful things to learn

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

Hope everyone good luck and success for the this contest

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

can any one give me the links of other contests DIV2 made by gridnevvvit :) thanks

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

I have never been able to solve Div-2 C type questions during contest... I hope i do solve it this time :) Good luck everyone

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

Время жестких задач настало!

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

I guess that someone black will win this round again.

249 div 2 only

247 div 2 only

UPD: yeah, I'm right.

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

    I think they are people which already have an old account at Codeforces but they just build a new account to become candidate master in 1 contest!

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

    let them
    I think making another account to compete in a div2 contest and be from top 10 ,that's the result of competing at div1 and lose every time or you can't make a significant score so you leave the real competing at div1 and try to stretch your muscles on a div2 players :)

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

    Black? Dat's racist.

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

      I don't think that what he was aiming to . Black is the non-rated contestant as he didn't enter any contest just as the color of your account

      And give me a break , you are putting Hitler photo and talking about racism ? =D

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

A question: Why everybody says that the scoring will be announced later?! Couldn't they publish it earlier?!

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

give me '-' pls

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

Когда последний раз было динамическое распределение баллов?

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

Good Luck to All contestants

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

Gd luck every one, hope I rise my rating this time :3 :D

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

Если вы не знакомы с термином математическое ожидание, то вы можете почитать про него по ссылке: http://ru.wikipedia.org/wiki/Математическое_ожидание

Дискриминация по возрастному признаку в действии :[

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

    Согласен, но зачем нужен гугл? Я нашел четкую формулу, чтобы высчитать ожидание

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

А почему нельзя смотреть уже взломанный код по заблокированной задаче?

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

Great round! Pretty interesting problems :)

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

Very hard D and E :(

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

Statements was unclear.

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

    What thing is unclear for you in the statements? I will try to do better statements in the future

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

      A problem, i read three times to understand statement. B problem, i didn't now is possible to collect any number of fruits(<b[i]) or you must collect all fruits from this tree.

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

    Did you find the exit you asked for?

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

      oh, i was nervous,i have made stupid mistake in A problem(i set INF 10^5 instead of 10^6)

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

    wasn't unclear ... just a little bit hard to understand . ;)

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

    yaap... statement was not clear to me too... :/
    but the notes after each problems helps me a lot... thanks to author for that... :)

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

How to solve problem D?

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

    There were a few key points :
    1) Number of swaps needed to make a permutation an identity permutation are N-C, where N is the number of elements and C is the number of cycles in the permutation. This can be proved using the statement 2 and 3 below (that it is unoptimal to swap outside cycle) and that a cycles of size M needs M-1 swaps to be sorted (provable by induction on M).

    2) Swapping two numbers in the same permutation cycle increases the number of cycles by 1. This can be proved constructively (take a cycle C, swap two elements and see that two new cycles are made.)

    3) Swapping two number from different permutations decreases the number of cycles by 1. Again, constructive proof.

    We have some number of cycles in the given permutation P, and we need N-M cycles in the target permutation Q. Hence keep on making an inter or intra cycle swap depending on which is bigger; and greedily choose the smallest index for lexicographically smallest solution. Complexity O(N2)

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

      The problem is tagged with disjoint-set unions. How can dsu's be used in this problem? What I did was to calculate the new disjoint cycles of the permutation resulting from every optimal intra/inter cycle swap.

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

        DSU can be used, for example, for joining cycles to cycle containing vertex 1 (The first case in editorial).

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

      Can you please provide a code where you have implemented the above idea ? Thanks.

      • »
        »
        »
        »
        10 лет назад, # ^ |
        Rev. 3   Проголосовать: нравится -17 Проголосовать: не нравится
        #include<iostream>
        #include<cstdio>
        #include<vector>
        #include<queue>
        #include<algorithm>
        #include<bitset>
        using namespace std;
        
        bitset<4000> vis;
        int phi[3000];
        vector<vector<int> > v;
        priority_queue<int> pq[3000];
        int ind[3000];
        int cyc;
        int n;
        
        void process(){
           for(int i=0; i<n; i++) while(!pq[i].empty()) pq[i].pop();
           vis.reset();
           v.clear();
           
           cyc=0;
           for(int i=0; i<n; i++){
              if (vis[i]) continue;
        	  int j=i;
        	  cyc++;
        	  vector<int> tmp;
        	  while(!vis[j]){
        	     tmp.push_back(j);
        	     ind[j]=v.size();
        		 
        		 pq[v.size()].push(j);
        		 if (tmp.size()>2) pq[v.size()].pop();
        		 
        		 vis[j]=1; j=phi[j];
        	  }
        	  v.push_back(tmp);
           }
        }
        int main(){
           scanf("%d",&n);
           vis.reset();
           for(int i=0; i<n; i++){
              scanf("%d",&phi[i]); phi[i]--;
           }
           
           process();
           
           int m; scanf("%d",&m);
           m=n-m;
           
           if (m>cyc){
              int diff=m-cyc;
        	  printf("%d\n",diff);
        	  for(int it=0; it<diff; it++){
        	     if (it) putchar(' ');
        		 int x,y;
        		 for(int i=0; i<v.size(); i++){
        	        if (v[i].size()==1) continue;
        		    x=pq[i].top(); pq[i].pop();
        		    y=pq[i].top(); pq[i].pop();
        		    break;
        	     }
        		 printf("%d %d",y+1,x+1);
        		 swap(phi[x],phi[y]);
        		 
        		 process();
        	  }
        	  puts("");
           }
           else if (m<cyc){
              int diff=cyc-m;
        	  printf("%d\n",diff);
        	  for(int it=0; it<diff; it++){
        	     if (it) putchar(' ');
        		 int x=v[0][0],y=v[1][0];
        		 printf("%d %d",x+1,y+1);
        		 swap(phi[x],phi[y]);
        		 process();
        	  }
        	  puts("");
           }
           else{
              puts("0");
           }
        }
        
      • »
        »
        »
        »
        10 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

        Here is my implementation of the above idea, as requested.

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

How to solve B?

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

    you must sort your trees by days and then model situation

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

      i stored the number of fruits on tree i in pp[i-1] and then iterated from 0 to n, picking as much fruits as possible. this is the submission http://codeforces.com/contest/441/submission/6845290 why is this approach wrong?

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

        Because you are summing the fruits you can collect to the Nth day...
        Here in your code — Line 22 :

        for (int i = 0; i < n+1; ++i)
        	{
                    ...
        

        Should be :

        for (int i = 0; i <= 3001; ++i)
        	{
                    ...
        

        UPD: That is one of your mistakes, but not that you got WA for.

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

Did everyone run the loop till the maximum day value for problem B? :P It was a pretty good hack.

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

system testing is faster than usual .

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

I'm new to CF and I read problem E first...

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

what what the correct approach to solve division 2 B problem?.i approached by first dealing with day i-1 and if some capacity is left then day i.i got wrong answer on pretest 5..here's the code http://ideone.com/mWCTzM

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

what was the correct way to solve DIV 2 B problem.i approached by first solving for day[i-1] and then for day [i] ...but got wrong answer on pretest 5 http://ideone.com/mWCTzM

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

    at first you should sort them by day.

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

    have three integer variables curPicked, prevDay and curDay. Then try to pick as many fruits as possible from the trees of prevDay and curDay while making sure that curPicked<=v.

    In my solution I created an array of 3000 elements for the days and for each day I saved all the different amounts of fruits that can be gathered on that day specifically. Note that the order doesn't matter.

    then it's just a matter of using the above 3 variables and the array effectively while taking care of the corner cases.

    Total time complexity: Θ(max of n)

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

    I see no reason, why you assumed that only for any particular day x, only one tree will have fruit at that day. Given your piece of code, day[st[i].day]=st[i].cap;.

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

      my mistake...at starting i remembered it but at last i forgot it.. AC by changing to day[st[i].day]+=st[i].cap; :'(

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

    corrected...the days were repeated...did'nt noticed it just changed day[st[i].day]=st[i].cap; to day[st[i].day]+=st[i].cap; and AC :'(

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

waiting for editorials....

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

Problem-C : Code implementation finished....contest 1 min remaining , when compiled--- several errors . After correcting errors...15 sec remaining>>>> finally, couldn't submit during contest !!!! Bad luck.. Anyways, contest problems are nice :)

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

what about editorials?

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

after solving probelm, A I could have solved problem B but I went for E because I found it really interesting but i failed to solved it in the end. Was it a wrong decision?

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

Can Any body tell me where is the main differnce between those two codes..???

  1. WA in test 10 Code -- B
  2. Accepted Code -- B

I use max value for the last limit for first one. And Use 3000 as last limit in 2nd one... Why I got WA... Cant find it.....

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

    I guess in the first code, you can still collect fruits that became available on day 3000, on day 3001, which you never visit, the second code, allowed for this case to occur, by having +2 beyond the maximum day.

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

      Thank you.... Feeling like i am the biggest idiot in the world... thanks for pointing the mistake out....

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

    Edited code of your first one : 6849997
    just written 3001 instead of 3000. Hope, you have got the point.

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

Rating is Updated

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

I have a bad day , i had WA on test 1 in problem C because i was use printf %d with a long long int without noticing , i don't know that it really cause many problems , in my local compiler the answer was the expected but in codeforces test no.

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

Hope to back ( green ) soon :)

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

That was a really fun round, thank you gridnevvvit!!

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

i_love_gridnevvvit Why unrated?

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

Anybody help me out with C?

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

    I tried solving the problem greedily

    we need k tubes, each with size >=2. Now k-1 tubes will be of size 2 and the remaining points will be the last tube. However I didn't have enough time to figure out how to print the final tube in a way that satisfies the condition

    for any integer i (1 ≤ i ≤ r - 1) the following equation |xi - xi + 1| + |yi - yi + 1| = 1 holds;

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

why the hacks list is not shown yet ??

Edit: Now they appeared :D

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

Would you please tell me what is wrong for this code? It is for 441B — Valera and Fruits :

http://codeforces.com/contest/441/submission/6850959

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

    Got it!, this is not optimal, because I should go for the trees that are getting rotten first.

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

Problem D was very nice for me; guess I learned about permutations solving it more than my recent abstract algebra course :D though I couldn't manage to debug my code in time :(

Thanks for the round!

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

6844888 I don't know why I get WA on test 11,I think my output at least in this test is correct.

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

I solve the problem B with O(n^2) (for 1 -> max_day {for 1 -> n}). If have test max_day = 3000 , n = 3000 then it will work O(3000*3000) = O(9000000), but it not TLE. I am surprising about this. Because this, I hacked some people with test 3000, 3000 and all unsuccessful. I am sad about this

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

Why can't I vote twice on a comment. It may happen that I voted somebody down by mistake but now I want to revert or give up