MIRZAPURI's blog

By MIRZAPURI, history, 3 months ago, In English

I’ve been seeing many people I know talking about how LLMs have "killed" CP. People are getting frustrated seeing leaderboards, and asking what is even the point now.

Lets take a close example: Chess after Deep Blue: In 1997, IBM's Deep Blue beat Garry Kasparov. It was a very shocking to those chess players (first such major AI like event ig), there was also similar discussion if chess was dead then as well. Today, any free chess engine on your phone can obliterate the reigning World Champion. After soo many years did chess really die? No, it became popular than ever.

Why? Because humans don't play chess to prove they are better than Chess engines. We play to beat the other guys, and more importantly, better than we were yesterday. CP is following the exact same trajectory.

The Harsh Truth: Online CP is a Gym, Not a Stadium Let's not sugarcoat it: Online CP, as a perfectly fair competitive arena, is effectively dead. With the current state of AI, online rounds are infested with automated solutions.

We need to accept that online platforms are now strictly for training. They are the gym. The actual "competition" will inevitably shift toward on-site, proctored environments like ICPC or strictly monitored finals. Online rounds are just sparring sessions to build your logic and speed.

Should we stop? Obviously not. If you are the type of person who would have done CP in the pre-AI era someone who actually enjoys the adrenaline of a green Accepted and the process of breaking down complex logic there is zero reason to quit.

If you were only in it for a superficial online rating to slap on a resume, then maybe it's time to move on. But if you are here to build a sharper brain and write highly optimized code, AI changes nothing about your personal growth.

As for dealing with the cheaters online, I keep my motivation simple:

I just tell myself: They literally need a supercomputer to make it a fair fight against me.

Full text and comments »

  • Vote: I like it
  • +197
  • Vote: I do not like it

By MIRZAPURI, history, 3 months ago, In English

Hello Codeforces!

Recently, I authored the problem Contest Wanderer. The problem asks a very simple question: If you start walking on an $$$N \times M$$$ grid that wraps around its boundaries (moving $$$a$$$ steps down and $$$b$$$ steps right), how many unique starting positions do you need to pick to guarantee you step on every single cell in the room?

Many people look at grid problems and immediately think of Grid Covering, DP with Broken Profiles, or Bipartite Matching. But this problem is a trap. It is purely Number Theory and Modular Arithmetic.

Visualizing the Cycle:

Two examples:

1. $$$4 \times 6$$$:

2. $$$3 \times 6$$$:

Things to notice:

-> No matter where you start on this grid, your path will eventually loop back to your exact starting coordinate.

-> Because the grid is perfectly symmetric, every single cycle will have the exact same length, L. (Note: this is the best point to make it intuitive, try some examples yourselves if you find it interesting).

If we know the length of one cycle, the minimum number of starting coordinates we need is simply:

$$$\text{Answer} = \frac{N \times M}{L}$$$

So, how do we find $$$L$$$ without simulating it?

Let's think in 1D:

1. The Row Cycle

Imagine just the rows as a single vertical column. You are on a grid of height $$$N$$$, and every step you move $$$a$$$ units down.

If you are at row $$$0$$$, you will return to row $$$0$$$ only when your total distance traveled downward is a perfect multiple of $$$N$$$. The smallest number of steps required to hit a multiple of $$$N$$$ while taking steps of size $$$a$$$ is dictated by the Greatest Common Divisor.

$$$\text{Row Cycle} = \frac{N}{\gcd(N, a)}$$$

2. The Column Cycle

The exact same logic applies to the columns. Imagine the columns as a horizontal row of width $$$M$$$, moving $$$b$$$ units right per step.

$$$\text{Col Cycle} = \frac{M}{\gcd(M, b)}$$$

Bringing it Together:

Here is where the mathematical intuition clicks. For the path to return to the exact $$$(0,0)$$$ coordinate on the 2D grid, both the row and the column must hit $$$0$$$ at the exact same time.

If the row returns to $$$0$$$ every 4 steps, and the column returns to $$$0$$$ every 6 steps, the first time they both return to $$$0$$$ together is at step 12. Mathematically, this alignment of two independent cycles is just their Least Common Multiple (LCM).

$$$L = \text{lcm}(\text{Row Cycle}, \text{Col Cycle})$$$

The Final $$$O(\log(\min(N, M)))$$$ Solution

With this visualization in mind, the code becomes incredibly simple. We can find the answer instantly using standard gcd operations:

#include <bits/stdc++.h>

using namespace std;

long long gcd(long long a, long long b) {
    return b == 0 ? a : gcd(b, a % b);
}

long long lcm(long long a, long long b) {
    return (a / gcd(a, b)) * b;
}

void solve() {
    long long N, M, a, b;
    cin >> N >> M >> a >> b;
    
    // Calculate 1D cycles
    long long rowCycle = N / gcd(N, a);
    long long colCycle = M / gcd(M, b);
    
    long long L = lcm(rowCycle, colCycle);
    
    long long totalCells = N * M;
    cout << totalCells / L << "\n";
}

int main() {
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}

Other problems with similar concept

  1. Grid Covering

  2. Drazil and His Happy Friends

  3. Yet Another Counting Problem

Hope this approach makes modular arithmetic on grids a bit more intuitive! Let me know what you thought of the problem.

Full text and comments »

  • Vote: I like it
  • +39
  • Vote: I do not like it