Ahad's blog

By Ahad, 11 days ago, In English

Hello Codeforces community,

I've been doing competitive programming for almost four years now, starting in May 2022. Before that, I had no prior experience with programming. Despite that, my progress has been steady:

  • Reached Pupil after 8-9 months
  • Reached Specialist in August 2023
  • Reached Expert in February 2024

Now it's February 2025, and despite practicing regularly, I haven't been able to stabilize in Expert. Sometimes I gain rating, sometimes I lose it, but overall, I feel stuck.

I know consistency is key, and I’m putting in the effort. But recently, I'm feeling confused about my practice approach. Am I solving the right problems? Am I missing something important?

Here's what my current training looks like:

  • I solve problems from past Codeforces contests, mostly Div. 2 B/C/D and sometimes harder problems.
  • I try to upsolve problems that I couldn’t solve during contests.
  • I participate in most rated contests and also do Gym contests sometimes.
  • Sometimes, I practice problems from diiferent platforms like LightOJ, CSES.

Despite all this, I don’t feel like I’m improving significantly. Sometimes, I solve a problem and feel like I just memorized a trick rather than truly learning something new.

I’d love to hear your thoughts and advice!

Looking forward to learning from your experiences.

Thanks in advance!

Full text and comments »

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

By Ahad, history, 5 months ago, In English

Contest Link: Battle of Brains 2024, University of Barishal

A. Unity

Tutorial
Solution

Author: Ahad

B. Help The Students

Tutorial
Solution

Author: B_a_k_a

C. Number System

Tutorial
Solution

Author: RiBNAT

D. Loyal Judge

Tutorial
Solution

Author: GIVE_UP

E. Who wins

Tutorial
Solution

Author: B_a_k_a

F. Find Difference

Tutorial
Solution

Author: RiBNAT

G. Balanced Madness

Tutorial
Solution

Author: B_a_k_a

H. Not a Giveway

Tutorial
Solution

Author: Ahad

I. Tourist

Tutorial
Solution

Author: GIVE_UP

Thanks for Participating!

Full text and comments »

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

By Ahad, history, 6 months ago, In English

Inspiration

When I first started with C++, I made a common mistake: I used mp[x] > 0 to check if a key existed in a map. I didn’t realize that this method actually adds new entries to the map if the key isn’t already there. This caused confusing bugs and unexpected results in my code. From this experience, I learned how important it is to use the right methods to check for key existence. In this blog, I’ll explain why this happens and show you better ways to check if a key is in the map without changing it.

Understanding map and unordered_map

In C++, map and unordered_map are containers that store key-value pairs. The main difference is that map keeps the keys in a specific order (usually ascending), while unordered_map stores keys in no particular order, using a hash function.

The Common Mistake

Wrong Approach

While it seems like a good idea, it actually causes a problem. When you use mp[x], the map tries to find the value for x. If x isn’t in the map, it insert x in the map as key with a default value (like 0 for integers). So, checking mp[x] > 0 actually adds a new entry to the map, increasing its size.

Right Approach

Approach 1
Approach 2

Demonstrating the Impact

All in one

As shown, using mp[2] > 0 increases the map’s size, while find() and count() do not.

Conclusion

Use mp.find(x) != mp.end() or mp.count(x) == 1. These methods are safer and won’t change the map’s size. They also make debugging easier by avoiding unexpected changes to the map, helping you understand and fix issues more easily.

Happy coding!

Full text and comments »

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

By Ahad, history, 10 months ago, In English

Contest Link: Intra Department Programming Contest 2023, CSE-BU

A. Shopping (Easy Version)

Tutorial
Solution

B. Shopping (Hard Version)

Tutorial
Solution

C. Create Square

Tutorial
Solution

D. Team Formation

Tutorial
Solution

E. Adjuctly or Exactly?

Tutorial
Solution

F. Good Prime

Tutorial
Solution

G. Upcoming Exam

Tutorial
Solution

H. Halal Food

Tutorial
Solution
Solution With Binary Search

Full text and comments »

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

By Ahad, 11 months ago, In English

Hello Codeforces!

I organized a contest at my university in November 2023, and I'm happy to welcome all of you to participate virtually or solve the problems later on.

Contest link: Intra Department Programming Contest 2023, CSE-BU

There are 8 problems and 150 minutes to solve them. Problems are not sorted by difficulty order. I recommend you to read all the problems.

This problemset were create for users with a rating range from 0 to 1400 but anyone welcome to participate virtually or upsolve the problems!

I would like to thank everyone who was involved in the contest preparation:

I tried my best to keep the statements short and clear and I hope you will like the problemset!

Happy Coding!

Full text and comments »

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