Alex2025_qwq's blog

By Alex2025_qwq, history, 5 weeks ago, In English

Hi everyone! Here’s a fun problem: Construct an n*m binary matrix such that all the 1-cells form a single 4-connected component, while maximizing the number of 4-connected components formed by the 0-cells. Two cells are considered adjacent if they share an edge. Is there an O(nm) construction with a provably tight upper bound on the number of zero-components? What is the tightest upper bound you can establish, and what are the best achievable time and space complexities for the construction?

  • Vote: I like it
  • -17
  • Vote: I do not like it

»
5 weeks ago, hide # |
← Rev. 4  
Vote: I like it 0 Vote: I do not like it

note: remember to handle n=1 or m=1

(btw im editing so much lol)

my construction (0: . and 1: #):

.#.#
####
.#.#
####
a[i][j] = 1 if (i % 2 or j % 2) else 0

its $$$\lceil n/2 \rceil \cdot \lceil m/2 \rceil$$$ 0 components

time and space is $$$O(nm)$$$

  • »
    »
    5 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it
    . # # #
    # . # .
    # # # #
    . # . #
    
    • »
      »
      »
      5 weeks ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it
      # # # # #
      # . # . #
      # # # # #
      # . # . #
      # # # # #
      
      • »
        »
        »
        »
        5 weeks ago, hide # ^ |
         
        Vote: I like it +26 Vote: I do not like it

        I wish obvious cheaters that clearly don't know anything about math tried to engage with this website and show their inexperience in the process

        Why are you here? Considering your name and profile picture it's probably not for job offers, just to ruin everything for people actually trying to learn? Stop

        • »
          »
          »
          »
          »
          5 weeks ago, hide # ^ |
           
          Vote: I like it -17 Vote: I do not like it

          "give me a very sigma reply to this comment considering that their recent submissions are ai generated"

          • »
            »
            »
            »
            »
            »
            5 weeks ago, hide # ^ |
             
            Vote: I like it +3 Vote: I do not like it

            Yeah? What's the point of submitting AI slop? Please explain

            • »
              »
              »
              »
              »
              »
              »
              5 weeks ago, hide # ^ |
               
              Vote: I like it -11 Vote: I do not like it

              prove that my submissions are generated by an llm or i slime you out like sergeant james doakes

              • »
                »
                »
                »
                »
                »
                »
                »
                5 weeks ago, hide # ^ |
                 
                Vote: I like it +3 Vote: I do not like it

                I was going to virtual the round later so I want to avoid spoilers but I'm willing to bet someone who appeared out of nowhere can get top 20 in a div2 without AI first try, unless this is a smurf account, then you should probably send your main/experience on another platform

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  5 weeks ago, hide # ^ |
                  ← Rev. 2  
                  Vote: I like it 0 Vote: I do not like it

                  what's the point of making a new account if i reveal my identity (no fun / lame)

                  p.s. good luck for the virtual (it was lowk horrendous, the contest) and try to prove the usage of ai after youre done

                  i'll wait for youse

                • »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  »
                  5 weeks ago, hide # ^ |
                   
                  Vote: I like it 0 Vote: I do not like it

                  the point is you cheated last contest and use AI to do all thinking dog here

»
5 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

It doesn't seem very Easy

»
5 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

4-connected means that removing any three nodes cannot make it disconnected. 4-connectedness implies all degrees are at least 4. The topmost 1-cell physically cannot have a degree larger than 3. The answer is all cells have to be 0s. QED

»
5 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

The best construction I was able to find after some experimenting was the same as potatoArmy but we set the bottom right corner to $$$0$$$ if $$$n$$$ and $$$m$$$ are even. I suck at proving things so it's up to someone else to figure out

Therefore it achieves $$$\lceil \frac{n}{2} \rceil \lceil \frac{m}{2} \rceil + [n \mid 2 \land m \mid 2]$$$ components (Iverson bracket notation)

»
5 weeks ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Short answer: Yes. A simple O(nm) construction exists, and the number of zero-components (call it z) obeys

  • Upper bound: z ≤ (n+1)(m+1)/3
  • Construction achieves: z ≈ (n−1)(m−1)/3

The two differ only by about (2/3)(n+m), so the leading term nm/3 is exactly right. The best possible density is one zero-component per 3 cells.

Upper bound proof

Omitted. Left as exercise to reader

Construction (≈ nm/3)

With 0-indexed rows i and columns j, set cell (i, j) = 1 if any of these hold, and 0 otherwise:

  • j = 0 (the left column is all 1s), or
  • i = n − 1 (the bottom row is all 1s), or
  • (i + j) mod 3 ≠ 0.
def build(n, m):
    return [[1 if j == 0 or i == n-1 or (i+j) % 3 else 0
             for j in range(m)] for i in range(n)]

Complexity

  • Time: Θ(nm). This is optimal, because simply writing the matrix out takes nm steps.
  • Space:
  • O(1) extra space if you stream the output, since each cell comes from a formula.
  • O(nm) if you store the matrix.

Caveats

  • Not exact for small grids. For example, on a 3×3 grid the optimum is 4 (four zero corners around a plus sign of 1s). The bound allows 5, and the formula above gives only 1. The bound is tight to leading order, but the exact optimum has an O(n+m) correction term I haven't pinned down. For small sizes, a brute-force search finds it.
  • Degenerate cases:
  • n = 1 or m = 1: the 1s must form one contiguous run, so z ≤ 2. This is reached when the length is at least 3.
  • Very thin grids (n = 2): it's better to handle these as a special case.
  • »
    »
    5 weeks ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    You can get a much better upper bound by just counting edges. The zeros are independent set.