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

Автор cry, 2 года назад, По-английски

Hellowo Codeforcers :3

sum and I are very delighted, ecstatic, enchanted, euphoric, excited, exultant, jubilant, overjoyed, and proud to invite you to participate in Codeforces Round 952 (Div. 4), which will start on Jun/11/2024 17:35 (Moscow time). There will be $$$8$$$ problems, with one split into two subtasks, to be solved in $$$2.5$$$ hours.

As usual, I have to copy and paste the following...

The format of the event will be identical to Div. 3 rounds:

  • 5-8 tasks;
  • ICPC rules with a penalty of 10 minutes for an incorrect submission;
  • 12-hour phase of open hacks after the end of the round (hacks do not give additional points)
  • after the end of the open hacking phase, all solutions will be tested on the updated set of tests, and the ratings recalculated
  • by default, only "trusted" participants are shown in the results table (but the rating will be recalculated for all with initial ratings less than 1400 or you are an unrated participant/newcomer).

We urge participants whose rating is 1400+ not to register new accounts for the purpose of narcissism but to take part unofficially. Please do not spoil the contest for the official participants.

Only trusted participants of the fourth division will be included in the official standings table. This is a forced measure for combating unsporting behavior. To qualify as a trusted participant of the fourth division, you must:

  • take part in at least five rated rounds (and solve at least one problem in each of them),
  • do not have a point of 1400 or higher in the rating.

Regardless of whether you are a trusted participant of the fourth division or not, if your rating is less than 1400 (or you are a newcomer/unrated), then the round will be rated for you.

We want to express overwhelming gratitude to the following individuals for making the contest possible:

Vladosiya and mesanu for coordinating the contest and reviewing the problems.

Dominater069, omeganot, Phi-001, flamestorm, nika-skybytska, willy108, ScarletS, mark, yuan-shen, Proof_by_QED, htetgm, buffering, TheYashB, haochenkang, ETL, natalina, MC3297, and lcsc0 for testing the round.

MikeMirzayanov for the usual.

We suggest reading all of the problems as we have put mucho effort into all of them. Best of luck, mis amigos!

UPD: Editorial

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

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

Auto comment: topic has been updated by cry (previous revision, new revision, compare).

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

orz

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

As someone who loves newbies, I hope this contest helps your rating!

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

Published 2 months ago! :O

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

We urge participants whose rating is 1400+ not to register new accounts for the purpose of narcissism but to take part unofficially.

Aye aye captain!

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

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

The round feels more solid with sum and cry as problem setters! :)

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

The best part of testing was the brotherly camaraderie I shared with Proof_by_QED.

Thanks to my friends cry and sum for setting the contest. It will be fun for any Div 2 competitors, so even if you are out of contest you should give it a try!

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

Will try to solve this round in rainboy style :)

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

Dear USACO Bronze Participants,

I write to offer my sincerest apologies for the unexpected challenge presented by Problems 1 and 3 in the recent USACO Bronze contest. It appears my attempt to craft engaging problems inadvertently led us down a rabbit hole more labyrinthine than anticipated.

Upon reflection, I understand how frustrating it must have been to encounter such formidable obstacles, akin to stumbling upon a hidden boss level in a seemingly straightforward game. Rest assured, it was never my intention to transform the contest into a virtual odyssey fraught with unforeseen perils.

As the architect of these challenges, I take full responsibility for their unintended complexity and any resulting vexation. Please know that I am committed to rectifying this misstep and ensuring future problems maintain a balance of accessibility and intrigue. Your feedback is invaluable in guiding this endeavor, so please continue sharing your thoughts and experiences.

In the meantime, I hope you'll accept my heartfelt apologies and know that your perseverance in the face of adversity is truly commendable. Together, let's navigate this coding journey with determination and resilience, knowing that each challenge only strengthens our skills and camaraderie.

With sincere regret and gratitude, cry

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

gotchu i will do my best even though im too highly rated

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

Last round, Div4 has just celebrated its 4th birthday, and it looks like we'll be saying goodbye to the SlavicG flamestorm mesanu era, meeting more and more interesting questions. Thanks all of you! :D

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

cry orz

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

sto orz (just two cats about to fight)

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

why is cry crying (crying emojis)

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

Ladies and gentlemen, finally I can say what I've always wanted to say at Div. 4 rounds announcements: My first unrated contest :^)

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

My first unrated contest , yay!

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

What if those whose rating is >= 1400 are restricted from registration? As we have seen this restriction in Div-1 contests. Then the submission queue and system testing will be smooth, I think. And you know, after the contest anyone can make submissions!

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

Every greeting synonyms of this blog could be the problem title of the whole Dashboard to make it more interesting!!!

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

Hopefully, I will make a comeback to reach CYAN after this round, insha-Allah.

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

very delighted, ecstatic, enchanted, euphoric, excited, exultant, jubilant, overjoyed, and proud

lol

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

I am gonna reach Pupil at this contest!!

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

create 2 new problems and make a div 3 also.

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

New faces at Div.4? Hehe, time to do a clean AK for appreciation's sake. Congrats on your first Div.4 round!

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

As an unrated contestant i hope to solve the problems

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

Looks like the problems will be named

A.delighted

B.ecstatic

C.enchanted

D.euphoric

E.excited

F.exultant

G.jubilant

H.overjoyed,

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

can i be rated ? i want to be rated because my rated is so ....

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

I registered when I was an Specialist. It still shows asterik(*) next to my name. Will this be rated for me?

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

Most casual announcement ever.

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

What is the penalty of resubmission in this round?

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

Hoping to perform better after 2 poor performances .

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

hope my rating>0

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

Is the Div4 the easiest competition game in CodeForce?

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

hopefully i can participate in a div4 soon!

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

let's go!!good luck everyone

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

In recent times, cheating is significantly increased and we the Newbies are suffering a lot :) It becomes harder to Newbies to increase ratings because of these cheaters.

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

Div 4 is like a Major Event to Us (Newbies). We eagerly wait for this round :D

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

I am delighted, ecstatic, enchanted, euphoric, excited, exultant, jubilant, overjoyed, and proud to participate in this round.

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

Well, this won't be rated for me, Good Luck to everyone

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

Hopefully my last rated Div. 4. Goodluck to everyone!

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

Hope to get positive delta

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

Hellowo :3

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

:)

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

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

Hope to reach pupil, also good luck to everyone!

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

All the best guys :))

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

what do these lines means? "ICPC rules + 12-hour open hacking phase.** Untrusted participants are not included in the official rank list."1.

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

My submission for problem D has been in queue for quite a while(>10 mins I believe). What should I do? Should I consider resubmitting?

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

Div 5

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

geometryforces... and negativedeltaforces for me :(

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

    where did you see geometry?

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

      D and E. To be fair D was just a simple observation- choose the row with the most number of '#'. But I just wanted to comment geometryforces for the fun of it :)

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

        Woah, nice stuff for D. I solved D the lazy way and take the mean value of all x-coordinates and y-coordinates of # cells. XD

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

          Wow, taking mean is an interesting observation. liked it! It might come in handy for some other problems, but maybe a bit of overkill for this problem. Anyways, I observed the first row where I get a '#', and I know that this is going to be the column of the center. For the later rows, I only checked if this column has a '#' in it. The center's row is the average of last such row and the first row.

          bool lookfst = true;
          ffr(i, 0, n){
              cin >> s;
              if(lookfst){
                  ffr(j, 0, m){
                      if(s[j] == '#'){
                          k = j;
                          lookfst = false;
                          h1 = i;
                          break;
                      }
                  }
              }
              else{
                  if(s[k] == '#') h2 = i;
              }
          }
          if(h2 == -1) h2 = h1;
          cout << ( (h2 + h1) / 2) + 1 << ' ' << k + 1 << '\n'
          
        • »
          »
          »
          »
          »
          2 года назад, скрыть # ^ |
           
          Проголосовать: нравится 0 Проголосовать: не нравится

          Can you explain to me why this method works? Thank you!

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

            It's easy to see that a Manhattan circle is centrally symmetric at its center — that is, if a circle is centered at $$$(h, k)$$$ and there exists a point $$$(x_1, y_1)$$$ in the circle, then there will always be another point $$$(x_2, y_2)$$$ also within the circle such as $$$\frac{x_1 + x_2}{2} = h$$$ and $$$\frac{y_1 + y_2}{2} = k$$$.

            We can keep discarding those pairs of points while calculating the average (coz' if a point has positive difference at x-coordinate from the center, its symmetric point will throw back at it with the same-margin negative difference, discarding themselves — and the same goes with y-coordinate as well). Eventually, there will only be the circle left, making it by default the average value of the x/y-coordinates over all points of that circle.

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

What is the approach in G (definitely not digit DP with such a big k, right)?

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

How to solve C?

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

    If a number in the list is the sum of all other numbers, then it is the maximal number in the whole list.

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

    Suppose you have an array a1, a2, ..., an. You need to choose n-1 elements in such a way so that their sum is equal to the not chosen element. But because all elements are non-negative, the only way for that to happen is if the not chosen element is maximum.

    Therefore you can keep track for each prefix two things: the current prefix sum, and the maximum element in that prefix. The prefix is good if sum — maximum = maximum.

    My submission: 265313130

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

Can anyone please help me with my solution for H1, it gives runtime error on test 5. 265363442 Thanks for your time.

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

    From my "investigation", Exit code is -1073741571 means stack overflow

    And the culprit is the dfs function with too many parameters. Maybe you should try reducing the number of parameters by using some global variables, and see if it works

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

how do you do G? and is H1 related to graphs or can we do it without it

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

even problem G got leaked

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

Is G a troll Problem???

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

Todays codeforces was very slow in loading too much frustrated

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

How to solve E in less than O(n^3) ?

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

Fun fact: E was originally proposed to be A of 887

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

how to solve G

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

hello @cry !

i faced a very big technical issue in todays contest of server issue and i was not able to submit many solutions , most of time it was buffering for human verification.

please help regarding this matter.

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

number theory forces

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

How 'F' has 7k+ submissions? In [newbie, pupil] range it's 4k+? Am i missing a very simple idea?

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

In Problem F, what was the safe upper bound to assume on the number of turns for the binary search? (Taking into account any overflow that may occur). I saw solutions with upper bound equal to 1e12, 1e13 and 1e17.

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

Nice problems, congrats for such a great contest.

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

Can someone pls give some hint in G. I got stuck there is it some kind of dp or math problem. And also hint for H2

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

the contest that i most enjoyed in a long time.

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

Can someone please explain the TLE in my submission of H1 265349188

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

    I think your profile pic kinda explains some of it.

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

      And the same code in C++ is accepted :( 265398650

      Generally I would've suspected Java, but in this case I saw some C++ submissions getting TLE on nearby test cases, and some accepted Java solutions. So I thought there is some problem in my code.

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

    I use C++ and my first solution without some optimizations got TLE, so I guess it does explain something lol

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

    I'm not an expert in Java, but I can suppose a couple of possible causes:

    • (more like an recommendation): DSU for highlighting components instead of dfs or bfs. Hypothetically DSU is quite able to pass time limit with such limitations, but to be sure I would recommend to use dfs or bfs in such simple case, since it's almost impossible for them to not pass the time limit
    • (My personal main suspect): Multiple usage of operations with hashset, especially "merge" of adjacent hashsets. Yeah, asymptotically all operations with hashsets in your solution work in $$$\mathcal O(n*m)$$$, but it's good to keep in mind that interaction with hash tables usually has a bad constant of working time, and I'm almost sure that it prevented your solutiong from passing

    If you are wondering, there is a determined $$$\mathcal O(nm \log(nm))$$$ solution with acceptable constant, and it also can be improved to determined $$$\mathcal O(nm)$$$

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

      Regarding the first point, the solution using DSU is coming faster than DFS and BFS.

      • DFS is slow probably because of deep recursion. TLE in test case 5, which is probably full # 265405138
      • The BFS solution is slightly slower, probably because of object creation (using $$$int[]$$$ as pair in Queue) 265403795
      • The DSU solution 265404399

      The second point is the main reason for TLE. Instead of precomputing the hashsets, I found them at the end only. The precomputation solution passed in C++ though :(

      Regarding using HashSet instead of TreeSet, in Java if there are a lot of collisions, then the buckets internally works as a TreeSet (refer this).

      So TreeSet and TreeMap are mainly useful when we want the values in sorted order.

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

In Problem E , for the Test case x = 4 , y = 3 , z = 1 and k = 6 , the optimal lengths i am getting is 2 , 3 , 1 , then answer will be is 3 ( (0,0,0) , (1,0,0) , (2,0,0) ) . but in problem statement it is given that answer is 4 . Anyone Please Explain !!!

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

Editorial

A: Switch the first letters of both words and print them. https://codeforces.me/contest/1985/submission/26521678

B: If n=3 print 3 else print 2. https://codeforces.me/contest/1985/submission/265225459

C: Keep track of sum and max of element as you scan through its prefixes. Count amount of times max = 1/2*sum. https://codeforces.me/contest/1985/submission/265232206

D: Track first and last #, when traversing grid, answer is the average of those. https://codeforces.me/contest/1985/submission/265242217

E: 1. Loop(a) through all values from 1 to x. If k divides a, loop(b) through all values y. If k/a divides b. Then c is k/a/b.

  1. answer is max of (1 + x — a) * (1 + y — b) * ( 1 + z — c)

https://codeforces.me/contest/1985/submission/265319163

F: 1. Store a min-heap priority containing time of each attack and attack.

  1. Until boss has 0 health, take top item of queue, and use attack.

  2. For each attack decrease boss's health by attack strength, and insert a new attack of strength of current attack and time of current attack + delay time.

  3. Answer is time of last used attack.

https://codeforces.me/contest/1985/submission/265293032

G: 1. Answer is ceil(10/k)^r — ceil(10/k)^l.

  1. Powers can be computed in O(log n) by squaring repeatedly storing in array, and using bit structure of n to multiply down until you get answer.

n^10 = n^8 * n^2.

https://codeforces.me/contest/1985/submission/265362645

H1: 1. Floodfill(look it up).

  1. Create a row and cols array

  2. During each floodfill,track which rows and cols can be reached(rows and cols within 1 of connected component. and size of connected component. Rows[row] += size, Cols[col] +=size. For each row and col reacheable.

  3. For each '.' add one to its row and col.

  4. Answer is max(max(rows),max(cols))

https://codeforces.me/contest/1985/submission/265337176

H2(take with grain of salt my solution passed with 1935 ms):

H1 but one must also have a point 2D array to track double counting. This happens in two ways.

  1. For each connected for each row and col reachable, track the possible double counting by adding size to points[row][col].

  2. For each '.' add one to points[row][col]

  3. Answer is max(rows[row] + cols[col] — points[row][col]).

https://codeforces.me/contest/1985/submission/265384992

Sorry if some of the later solutions are messy.

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

why is carrot not working ????

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

My H1 runs surprisingly slow, can someone tell me why? I'm sure it's something in my implementation but I don't know what. Feel free to hack if possible: 265367113

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

I enjoyed the problems a lot, G and H1 were especially neat. Thanks!

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

Hint for H2, please. For H1, I individually checked each for each row; what's the size that's getting added if we set all cols in the row to '#, i did the same for cols and chose the max as ans,

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

Codeforce server becomes very slow specially on div4 contests

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

Cloudfare forces, jokes aside it was a really good contest for me. I am not that good but I xould solve upto E! And I guess F would have required a solution with priority queue, but I was too slow to implement it.

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

In G, can someone explain why $$$k \gt 9$$$ doesn't matter?

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

Why is my code for problem H1 giving TLE on test 10?

I used dfs algorithm keeping ids of each component in the visited grid and stored the size of each of the component ids in a map.

I then traversed the grid row-wise and column-wise to get my answer.

Here is the link to the submission : https://codeforces.me/contest/1985/submission/265376706

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

    number of component can be $$$\frac{n\times m}{2}$$$ (think of a chessboard). So the $$$id$$$ in your code is $$$O(n * m)$$$, thus your for loop that involves constructing $$$visid$$$ is $$$O(n^2\times m)$$$.

      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (grid[i][j] == '#' && vis[i][j] == 0) {
            dfs(id, i, j, grid, n, m, cursize, vis, idsize);
            id++;
            cursize[0] = 0;
          }
        }
      }
      ...
      for (int i = 0; i < n; i++) {
        int temp = 0;
        vector<int> visid(id, 0);
    
  • »
    »
    2 года назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +3 Проголосовать: не нравится

    Your code probably fails in a test like this:

    .#.#.#
    #.#.#.
    .#.#.#
    

    Your solutions runs in $$$O(max(n,m) * id)$$$ (because of declaring the vector $$$ids$$$ each time). The size of $$$ids$$$ may be large. In order to prevent this, you can use a global $$$ids$$$, and a queue to keep track of the components you choose. In the end of the iteration, you can empty the queue and reset only those $$$id$$$'s that were changed.

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

Just hoping that the cheaters are caught:( . I saw many codes which looks like they have been copied from some other sources.

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

can any one tell me what is the wrong 265398472

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

I have solved F using priority queue Submission, i think its quite complex implementation of mine. Could someone check and tell me whether we have a better and neat approach for the same question. Also I would like to get the hints to solve this using binary search. Thanks

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

When will people stop?

In most recent hacks, I didn't even check anything other than these three lines:

unordered_map<int, char> grid[MAX_N];
unordered_map<int, int> component_id[MAX_N];
unordered_map<int, int> component_size;

and just one test data was enough to hack like 30 submissions which had these lines. Now where is the source of this?

To explain the hack: Apparently, there has been a long-living bug with GCC's unordered_map::clear() that it keeps its bucket size, so clearing takes $$$\mathcal{O}(x+k)$$$ time where $$$x$$$ is the number of elements and $$$k$$$ is the bucket size. While $$$x$$$ is reset to 0 everytime we call clear(), $$$k$$$ remains the same so we can just insert a whole bunch of elements in the map in the first test case, and with the remaining 9999 cases we can spam $$$n=m=1$$$ so that it calls clear() 9999 times, each taking $$$\mathcal{O}(nm)$$$ time where $$$n$$$ and $$$m$$$ comes from the first test case.

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

    That's interesting. We should avoid using unordered_map. Is initiating the map locally for each test is better?

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

      In most cases it's better not to use unordered_map at all. In this case though, either making it a local variable, or just doing mp = unordered_map<int, int>(); instead of mp.clear() also works.

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

        Initiate local also variables consume time also. At some point, we can get TLE if we declare local variables and it got AC when moving to global variables. But yeah, will keep in mind to avoid using unordered_map.

        OOT, observing your hacked solution, I cant help but notice that people do like to write stories in their code :)

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

See this, 265373769.

Lots of useful statements like

for(int i = 0 ; i<56 ; i++){
        if(i == 50){
            break;
        }
    }

to escape plagarism.

Are such tricks good enough to escape plagarism? MikeMirzayanov Vladosiya

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

Idk why I'm posting it now, but here's a testcase for hacking problem F:

1 200000 100 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

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

In F, if you accumulate the total damage at the first iteration of binary search (check(mid)), it can go to $$$n*a*mid$$$, with mid going at least to $$$\frac{h*c}{2}$$$ which is around 2e10. So the total accumulated sum can go up to 8e20 at best, which explains the reason why many got hacked in F (it overflows, but overflows to the point where the accumulated sum produces negative results when casted to int64_t. This causes check(mid) to be false (while it is actually true), thus it creates a wrong answer (the range of binary search is now wrong)). To fix this it is usually needed to fast break out of the loop or use __int128.

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

I enjoyed a sound sleep after scoring 6 problems. After waking up, my 'F' got hacked!!! Thanks for not hacking the submission before my sleeping time.

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

Can anybody tell me what is the use of hacks, And what happens if I successfully hacked others solutions??

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

    Hacks here are tests added by users during a contest (Div.1+Div.2, not Educational) or in a hacking phase (Educational/Div.3/Div.4) that satisfy the problem constraints, yet make an Accepted solution (the one you're hacking) either giving different answers from the jury (rendering WA) or stumbling onto TLE/MLE/RTE/etc..

    For those rounds with hacking phase, you simply contributed to the final testset. For Div.1/Div.2 rounds, you actually gain points when hacking successfully (but before doing so you have to lock your problem first, thus not being able to resubmit in-contest and now prone to other hacking you should that solution is incorrect as well), though chances are low as present rounds seem to have pretty strong testsets to start with.

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

My solution for question F got hacked thereafter I submitted the same solution and it got accepted, then the solution got hacked. Please help!!

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

Problem F guarantees that the sum of h and n over all test cases does not exceed 2*(1e5) ... However, it seems like this constraint has not been enforced in quite a few hacks generated.

For example, https://codeforces.me/contest/1985/hacks/1041402/test

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

    Nah, the test you showed clearly falls within constraints.

    There's only one test with $$$h = n = 2 \cdot 10^5$$$, which is just right at the upper bound limit for both $$$\sum h$$$ and $$$\sum n$$$. Notice that there are no limits on $$$\sum a$$$ or $$$\sum c$$$.

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

can someone tell why is dsu giving tle in H1

»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
  • I solved 6 problems with 219 penalty.
  • I can find myself at the 854th place in the 'Common Standing' page.
  • But when I go to the 'Friends Standing' page it says I'm on the 1312nd place.
  • Also the 'Rating Changes' and 'Friends Rating Changes' pages list me on the 1312nd place.

Can someone help me to understand this discrepancy?

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

Hello I want to ask about something I solve 2 questions in div 4 correctly from first try and my rate decreased why ?!

»
2 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится
#include<bits/stdc++.h>
using namespace std;
#define int long long
int mod=1e9+7;
vector<vector<int>> mult(vector<vector<int>>& a,vector<vector<int>>& b){
    int r=a.size();
    int c=b[0].size();
    int comm=b.size();
    vector<vector<int>> ans(r,vector<int>(c,0));
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            for(int k=0;k<comm;k++){
                ans[i][j] = (ans[i][j] + (a[i][k] * b[k][j])%mod)%mod;
            }
        }
    }
    return ans;
}
int func(int n,vector<vector<int>>& mat,int node){
    vector<vector<int>> ans(n,vector<int>(n,0));
    for(int i=0;i<n;i++) ans[i][i]=1;
    while(n>0){
        if(n%2==1){
            n--;
            ans = mult(ans,mat); 
        }
        else{
            n/=2;
            mat = mult(mat,mat);
        }
    }
    return ans[0][node];
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,m,k,a,b;
    cin >> n >> m >> k;
    vector<vector<int>>mat(n,vector<int>(n,0));
    for(int i=0;i<m;i++){
        cin >> a >> b;
        mat[a-1][b-1]++;
    }
    cout << func(k,mat,n-1) << endl;
    return 0;
}

Can someone please see what is the inefficiency here? When I manually run it on custom invocation in codeforces it says "Memory limit exceeded" however I have passed all the matrices by reference. Also, the code given here for graph paths — 1 is getting accepting by using a recursive implementation of binary exponentiation. I have used iterative implementation, still it is not accepted. Kindly have a look. This is for problem Graph Paths -1 of CSES under mathematics section

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

I participated in this contest and have been accused for Plagiarism, with the user newbie333 265377444 while here is my submission 265318802. I have had no prior contact to the user, though our answers are visibly similar, Like idk how real are the chances of this happening, but i believe the approach written in solution is very standard.

Also there is a significant difference between the time of submission between us around an hour or so, Please consider this as mere coincidence and make this round rated for me again.

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

Good contest!