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

Автор MrPaul_TUser, история, 3 года назад, перевод, По-русски

1593A - Выборы

Идея: MikeMirzayanov

Разбор
Решение

1593B - Делись на 25!

Идея: MikeMirzayanov

Разбор
Решение

1593C - Спасти больше мышек

Идея: коллектив студентов ИТМО

Разбор
Решение

1593D1 - Все одинаковые

Идея: MikeMirzayanov

Разбор
Решение

1593D2 - Половина одинаковых

Идея: MikeMirzayanov

Разбор
Решение

1593E - Садовник и дерево

Идея: MikeMirzayanov

Разбор
Решение

1593F - Красно-чёрное число

Идея: MikeMirzayanov

Разбор
Решение

1593G - Меняя скобки

Идея: nastya_ka

Разбор
Решение
Разбор задач Codeforces Round 748 (Div. 3)
  • Проголосовать: нравится
  • +54
  • Проголосовать: не нравится

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

Can someone explain the solution to F pls

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

d2 is really intresting.

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

It seems that in the tutorial for A, the answer should be max(0, max(b,c) + 1 — a) (as in the solution code), instead of min(0, max(b,c) + 1 — a).

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

We don't need that extra array to recover answer string. We can store masks in DP and recover the answer from that. Submission with comments : 131983798

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

Your dp is so messy.(F) -__-
Good problemset btw.

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

For the E problem, will the standard graph bfs not work? I pushed all the leaves ( adjacency list size == 1 ) to a queue and assigned them a distance of 1 ( distance = number of times the operation has to be performed to cut off that node ). Then I performed a bfs assigning increasing distance. Answer is simply all the nodes whose distance is greater than k. This is failing though. Please if somebody could help me out. Thanks in advance

https://codeforces.com/contest/1593/submission/132264294

UPD : I changed the visited logic to an in-degree logic while preserving the bfs (AC : 132341078). Hope somebody finds this helpful. Thank you dedsec_29

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

    Once you mark a node visited, your code will never update its distance. But this is incorrect. You have to mark a node visited only when it becomes a leaf. If you mark it before it becomes a leaf, d[i] will no longer denote iterations after which the node is no longer part of tree

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

      "If you mark it before it becomes a leaf, d[i] will no longer denote iterations after which the node is no longer part of tree."

      Can you justify this with a counter-example please? I tried a lot of manual cases (Sample cases passed too), every time the node gets marked as visited, it is correctly assigned the distance from the closest leaf. Say the distance of the node is 3 from the closest leaf and k=3, so that node will be cut off at the end of all k operations, right? Or am I missing something? Thanks again.

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

        Take this test case for example:

        1
        8 2
        1 2
        2 3
        3 4
        4 5
        5 6
        6 7
        8 3

        Your output: 2
        Correct output: 3
        Your code deletes node 3 as you mark the distance 2 for it, but it will be deleted in the 3rd iteration, so d[3] should be 3, not 2

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

    Thanks man

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится
  • Can Someone help with the time complexity of this code: https://codeforces.com/contest/1593/submission/132395142 for problem D2.
  • I have used dp table for calculating the maximum gcd possible when I consider exactly n/2 numbers( because I have to make atleast half elements equal)
  • dp[i][cnt][last] stores set of GCDs that are possible after considering cnt number of elements upto ith position in the array with index of previous selected element as last.
  • It got submitted with 15ms runtime. According to me, the time complexity of this code is O(n^5 * (log(max(Ai)) + log(n))). I want to know whether I am wrong with the time complexity or test cases are not strong enough !
Reason behind asking this question
»
2 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Did anyone solve F using meet in the middle idea ?

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

    I'm trying to do it here but I need a way to combine the answer faster, I'm doing it in O(2^(n/2)*a*b) but it didn't pass.

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

My idea for E was to look at one diameter of the tree and take a middle point in that diameter. After that i root the tree in this middle point and after that it's easy but unfortunately i got memory limit exceeded. Is this idea works?

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

    yes this idea works, be careful on how you are finding middle point(s) when diameter is even or odd. code

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

CAN F QUESTION DE DONE USING MEET INT THE MIDDLE?

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

    Yes, but you need to write it with very low constant factor. You can check my submission here

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

deleted

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

I found it in the code written in D1, and when I copied the code and confirmed it, it gave me: WA on test 1 After two years I discovered the error In the coming days, we must test the code before publishing it :)

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

    When removing a "break", the code became valid, and the reason for this is that the written code must come in a smaller number, and this is a simpler code number.

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int main()
    {
    	
    	int t=0; cin>>t; 
    	while(t--){
    	    bool s=1;
    	    int n,mn=1e9; cin>>n;
    	    int x[n];
    	    for(int i=0;i<n;i++){cin>>x[i]; if(i>0&&x[i]!=x[i-1])s=0;mn=min(mn,x[i]);}
    	    if(s)cout<<-1<<endl;
    	    else{int ans=0;
    	    for(int i=0;i<n;i++){
    	        ans=__gcd(ans,x[i]-mn);
    	    }
    	    cout<<ans<<endl;
    	    }
    	}
    
    	return 0;
    }
    
»
6 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can anycody give a counter case in which this approach fails for the problem E (link to problem)? I am not able to think about a counter case thanks Submission

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

Can anyone help me with this WA on test 2 please 241674222