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

Автор chokudai, история, 4 года назад, По-английски

We will hold AtCoder Beginner Contest 259.

The point values will be 100-200-300-400-500-500-600-600. We are looking forward to your participation!

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

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

Loved problem D (^-^)

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

Honestly, that A and B where worst problems I ever had on atcoder. Abc is supposed to be constest for beginner partitipants, not beginner problem setters.

I am disapointed because quality of atcoder contests was very good before.

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

I would recommend whoever wrote B to consider never problemsetting again.

E and F were fun though.

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

Found problem B harder than E. Maybe I need to pickup my high school mathsbook again.

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

    Can you explain your approach for E please ?

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

      Lets consider the lcm of all numbers initially. We know that lcm is the maximum count of each prime among all the numbers. So we can store the maximum count of each prime in a map. The lcm will change only if the ai has a prime with its count equal to maximum count of same prime and no other ai has the same prime with the maximum count. We could do so by storing count of ai that have their count of that prime equal to maximum count. Lastly we need to check whether the lcm of the whole array is possible or not after performing any operation, we could do so by checking if for any ai there is no prime which has unique maximum count or we could just check if answer is less than n and than we could simply add 1 to our answer.

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

        I did something similar but couldn't understand last part of your explanation can you provide me feedback on below here was my approach (obv wrong).

        • Maintain a vector of power of each prime and sort , so we know which number(s) in the input have this maximum power of prime. If there are two number with max power of considered prime our lcm won't change ever since there would always be one of the two numbers present. This needs to be checked across all primes for a given number.

        • If the above doesn't hold then a number has one or more primes with max power and removal of this number should change the lcm so add 1 to the answer there.

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

          Yeah so it maybe possible that the lcm wont change for a possible operation so we need to add 1 to our final answer for it, so we see that if the answer is n then every operation changed the lcm else if answer < n then there exists atleast 1 index for which our lcm won't change so we could just increment 1 to our answer.

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

A: Statement is so hard to understand. Bruh

B: Why is this a problem???

C: Decent

D: Repeated problem but now with gEomeTRy

TLDR: This is actually WaCoder. The first half of problemset is shit

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

I used bfs but 6 testcase are failing is it due to overflow im not getting idea?? Plzz help

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

problem E can solved with divide and conquer + hashing. code

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

In editorial of problem G:

Spoiler!!!

Shouldn't it be?:

Another Spoiler!!!

Also, I don't really understand why solution works :(

To be more precise, I don't understand why do we add edge from:

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

    It's problem G I think?

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

      Yeah, sorry!

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

        It's because in the problem statement, if the value of the intersection square of the two peoples' choices is less than 0, a very large penalty is added, so we cannot let them choose this intersection point. In the graph, cutting an edge corresponds to choosing an intersection square, and setting its capacity to infinity in a minimum cut ensures that it will never be cut(chosen).

        Also yeah I think they messed up the ordering on C and R.

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

          But why is it true that if $$$C_j$$$ and $$$R_i$$$ are both chosen, we'll always need to cut this edge with weight $$$inf$$$?

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

            If they are both chosen and we do not cut this edge, there will be a complete path from $$$S$$$ to $$$T$$$. Choosing $$$R_i$$$ means that there is a complete path from $$$S$$$ to $$$R_i$$$, but not from $$$R_i$$$ to $$$T$$$. The similar is true for $$$C_j$$$.

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

              okay, if there is a path from $$$S$$$ to $$$R_i$$$, also there's a path from $$$C_j$$$ to $$$T$$$, and also there's an edge from $$$C_j$$$ to $$$R_i$$$, why does it mean that there will be a path from $$$S$$$ to $$$T$$$? I'm very sorry for being stupid, but I really don't understand :(

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

                I believe they fixed the editorial to " $$$R_i$$$ to $$$C_j$$$ " already.

                Edit: Oh they didn't, but just look at brunovsky's comment.

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

                  But author's code says otherwise:

                  g.add_edge(h+j, i, inf)

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

                  What in the world... And when I change the edge to $$$R_i$$$ to $$$C_j$$$, it got WA... Now I'm confused too...

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

                  My friend helped me to understand the author's solution. Actually, we take a row to the answer, if it's connected with T in the cut.(then we delete absolute sum of negative elemets) And we take a column to the answer if it's with S in the cut (also we delete absolute sum of negative elements)

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

                  Can u elaborate on this a little more bashkort, I am struggling to understand how this definition helps and how is it justified

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

                  I'll try to :)

                  In the beggining we added all positive elements to the answer. Then we want to create a graph, then find a minimum cut from $$$s$$$ to $$$t$$$ in this graph and subtract this value from the answer.

                  We will create graph as editorial says, and I'll show why this graph works.

                  So I say that we take some row $$$i$$$ to the answer if it is connected with $$$t$$$ in the minimum cut. Else if we don't take it, it will be connected with $$$s$$$ in the cut.

                  Also we take some column $$$j$$$ to the answer if it's connected with $$$s$$$ in the cut. Else if we don't take it, it will be connected with $$$t$$$ in the cut.

                  So why does this work: If we take a row $$$i$$$ to the answer, so it won't be connected with $$$s$$$ in the answer $$$= \gt $$$ then we already added every positive element from that row in the very beggining, so now if we take it to the answer, we have to add negative values too (so now we have to cut edge from $$$s$$$ to $$$i$$$, because as I said "we take some row i to the answer if it is connected with t in the minimum cut"). So because of this we create edge with weight = sum of absolute values of negative elements in the row $$$i$$$.

                  This edge will go from $$$s$$$ to $$$i$$$, so if it's in the answer, we subtracted this edge, or didn't subtract otherwise.

                  You can apply pretty much the same logic for columns.

                  Now let's have a look at edges between rows and columns. If we took both row $$$i$$$ and column $$$j$$$, then there is a path from $$$i$$$ to $$$t$$$, and also there is a path from $$$s$$$ to $$$j$$$. Then if a[i][j] < 0, we have to cut edge from $$$j$$$ to $$$i$$$ with weight $$$inf$$$. It's pretty obvious that's it's not optimal.

                  If we did't take both of $$$i$$$ and $$$j$$$, then need to subtract the edge between $$$i$$$ and $$$j$$$, because otherwise there will be a path between $$$s$$$ and $$$t$$$.

                  I hope you understand now :D

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

    Should be $$$R_i\to C_j$$$ with capacity $$$a_{ij}$$$ if $$$a_{ij}\geq 0$$$ else $$$+\infty$$$. For more context, see image segmentation on wikipedia.

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

      Thanks! But why do we add edge with capacity $$$+∞$$$ from $$$C_j$$$ to $$$R_i$$$, but not from $$$R_i$$$ to $$$C_j$$$?

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

        Because we connect $$$S$$$ with $$$R$$$ and $$$C$$$ with $$$T$$$. Otherwise, You can swap the order but you must guarantee that the connected ways are flowing from $$$S$$$ to $$$T$$$.

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

          Author's code says that we add edge from $$$C_j$$$ to $$$R_i$$$

          Then, if there is a path from $$$S$$$ to $$$R_i$$$, also there's a path from $$$C_j$$$ to $$$T$$$, and also there's an edge from $$$C_j$$$ to $$$R_i$$$, why does it mean that there will be a path from $$$S$$$ to $$$T$$$?

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

        Ok it appears the construction in the editorial is a bit different from the usual segmentation setup. The later is probably easier to understand — see the submissions of those on top of the leaderboard.

        Here's my interpretation (see the article on wikipedia):

        • We earn $$$r_i=\sum_{j}a_{ij}$$$ if we assign row $$$i$$$ to the foreground, $$$0$$$ to the background.
        • We earn $$$c_j=\sum_{i}a_{ij}$$$ if we assign col $$$j$$$ to the background, $$$0$$$ to the foreground.
        • We pay $$$b_{ij}$$$ if we assign row $$$i$$$ to foreground and col $$$j$$$ to background, where $$$b_{ij}=a_{ij}$$$ if $$$a_{ij}\geq 0$$$ else $$$b_{ij}=\infty$$$ to prevent this altogether. This adds an edge from row $$$i$$$ to col $$$j$$$.

        Now we can build the standard segmentation graph and not think about this any further, but consider some row $$$i$$$. This would add either edge $$$s\to i$$$ with capacity $$$r_i$$$ if $$$r_i \gt 0$$$ or edge $$$i\to t$$$ with capacity $$$-r_i$$$ if $$$r_i \lt 0$$$. But in the second case the edge is completely useless ($$$r$$$ has no other incoming edges) so you may as well ignore it. Similarly for cols.

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

Sorry but according to this post in Chinese(You don't have to understand Chinese but just see the code), GREEDY ALGORITHM can pass problem G, and there's just a hack data below.

Well if you can't see the code and the hack data, here I will copy it :

int main() {
    qread(n, m);
    rep(i, 1, n) rep(j, 1, m) qread(a[i][j]);

    rep(i, 1, n) {
        ll sum = 0;
        rep(j, 1, m) sum += a[i][j];
        if(sum > 0) ans1 += sum, v[i] = 1; 
    }
    rep(i, 1, m) {
        ll sum = 0;
        rep(j, 1, n) if(v[j] && a[j][i] < 0) {
            sum = -1;
            break;
        }
        else if(!v[j]) sum += a[j][i];
        if(sum > 0) ans1 += sum;
    }

    memset(v, 0, sizeof v);

    rep(j, 1, m) {
        ll sum = 0;
        rep(i, 1, n) sum += a[i][j];
        if(sum > 0) ans2 += sum, v[j] = 1; 
    }
    rep(i, 1, n) {
        ll sum = 0;
        rep(j, 1, m) if(v[j] && a[i][j] < 0) {
            sum = -1;
            break;
        }
        else if(!v[j]) sum += a[i][j];
        if(sum > 0) ans2 += sum;
    }

    cout << max(ans1, ans2) << '\n';
    return 0;
}
4 4
-1 -1 100 100
-1 100 100 100
100 100 -1000 -1000
100 100 -1000 -1000
»
4 года назад, скрыть # |
← Rev. 2  
Проголосовать: нравится +7 Проголосовать: не нравится

Out of all problems from A to E, I think only C,D were Decent

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

For problem F, my first idea is based on greedy algorithm (inspired by Kruskal's algorithm), i.e., sort edges in decreasing order of weight, and choose from large ones to small ones as long as the "rule of degree" is not broken. But, I really wonder why this does not work? What are the counter-examples?

By the way (I am sorry that this is off topic), I find KrK in the standings!!! I am sorry to disturb you here, but you are really a legend!! During past years, I kept practicing by virtual participation in codeforces, and I usually saw you in standings, and witness your persistence and improvement. Early codeforces rounds usually do not have detailed tutorials, and it is difficult for me to understand for most of the time. During that tough period, I learned a lot by reading your solutions. The codes are clean, simple, and it helps me understand the idea behind the solution quite a lot. I am very glad to attend a true contest with you this time.

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

Can anyone give me any test case for problem C that fails in my submission. My approach seems similar to the official editorial.

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

This contest made me learn new functions like sqrtl, cosl, sinf, tan2 and other due to lack of accuracy. I've never had so many WAs during contests. Hope there will be less such problems, or at least not at that positions.

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

Solving today's contest reminded me of my JEE days :)

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

Typo?

1. ca*m* be chosen at most d_v times. 

Editorial of F, Line 13

plz fix it thx :)