Week 1
Week 1
Week 1
Be gin()
Coding Club, IIT Guwahati
CONTENTS
Prerequisites (Expected Time: 1-2 days
Resources
Website
Competitions
Implementation (Expected Time: 1 day
STL (Expected Time: 1-2 days
Maths (Expected Time: 0-1 days
AD-HOC (Expected Time: 0-1 days)
For this course, there are no prerequisites as such. But to start CP you will
need a decent level of knowledge of at least one programming language
General Order of Preference:-
Environment)
In simple words, an IDE is an environment that you will be using to write
your code, compile it and view the output. A suitable and well-equipped
IDE is very important, and not setting it up in the right way may cause
trouble in the future.
Don’t mess up while setting it up otherwise you will easily waste days
fixing it!!
LANGUAGE
What we are going to recommend is the fastest and preferred way to
learn C++ / Python. These are short videos, yet they are more than
sufficient.
Resources for C+
Bucky’s Tutorial: Watch lectures 1 to 41 and 71 to 73.
Solve the First 10-20 problems from hackerrank just to get comfortable
with the language you chose.
Note: Do not waste much of your time learning the language ( getting
into tiny details).
VS Code extensions:
To install these extensions, look for the “Extensions” button on the left
cases from the website which you won’t have to write again and
again. To work with this you also have to install the Competitive
Companion .
These are reusable code pieces that can help you avoid re-writing the
same code. You can make them in both VS Code and Sublime Text.
4. Header Files
C++14 and above and it is not directly available for Mac users.
Mac users can refer this video. The folder with include files may not
be the same. To find that, you can make a C++ file, type
RESOURCES
Handbook (CPH):- You can find 90% of the things you want to learn in
this book, but reading this book completely and then starting to solve
problems is not recommended. Just refer to the book when you come
across a topic that you haven’t heard about before
CSES:- The author of the Handbook has also made a compilation of
300 really good and conceptual problems which covers almost all CP
topics. But it doesn’t contain problems sorted according to difficulty so
you will have to estimate it using solve count
USACO Guide:- This is literally the “one-stop shop”. This website is
generally referred to as USA computing Olympiad aspirants and it has
everything in sorted order. And it has divisions like Bronze, Silver, and
Gold. It will mostly refer to the Handbook and explain solutions to
CSES problems as well
CP-Algorithms:- Contains all CP topics but again not in sorted order of
difficulty. So, refer to it only if you are stuck on a topic and couldn’t find
it in the Handbook
WEBSITES
Some websites from where you can learn and compete and some
important competitions
Contests are mainly of the following types:- Div 4, Div 3, Div 2, Div 1,
Do try to solve all the problems whose ratings are <= your rating +
300. If you are not able to solve the problems, refer to their editorial.
If you still don’t understand the solution, discuss it with your friends
Codechef:
Google Contests:- Don’t miss any of them unless you have an exam at
the same time
Google Kickstart:
8 times a year. All 8 contests are independent
Sometimes the problems are irritating but still, it's a google
contest
Google Codejam:
Held once a year. Probably the biggest CP contest
5 rounds in increasing order of difficulty, with elimination in each
Round
Prelims->Round A->Round B->Round C-> world final
Google Hashcode:
Held once a year and is very different from normal CP contests
You have to come up with a solution to a problem and improve it
to gain more points. Problems couldn’t be solved completely
Meta HackerCup:- It is also a once-a-year contest in topological order
just like Google Code Jam
ACM ICPC:- Held once a year and the Biggest CP contest for college
students. Also in topological order
Online -> Regionals -> World Final
Codechef SnackDown:- Held once every two years. The Next will be in
2023.
IMPLEMENTATION
(Expected Time: 1 day)
After we have learned a language, we can now get started with actual
problem-solving.
Here are some resources which will help you understand time
complexity: -
3. This blog might help you in avoiding Time Limit Exceeded error
In Python3, the int type stores large enough numbers, so you don’t have
to worry about the value which will be stored in the variable.
In C++, int is a data type that takes up 32 bit of space and can store
integers ranging from -2,147,483,648 to 2,147,483,647. However, the
answers in the problems very often go over that range and give wrong
output. This is called integer overflow. Hence, we can use long long data
type over int in such cases. You can read more about it here. This can be
really frustrating if not taken care of as the code gives wrong output even
when your approach is correct.
*We have attached the codes with solutions. If you still have any doubts
feel free to ask us in the discord channel.
*In general, the solutions to the problems can be found in the Editorial/
Tutorial section on websites like Codeforces, Atcoder etc. For CSES, most
of the solutions can be found on google.
At the core of the C++ Standard Template Library are the following three
well-structured components − containers, algorithms, and iterators.
Basic knowledge of STL is quite handy, and in fact, necessary for
competitive programming.
Resources
Vector: One of the most powerful and frequently used STL containers.
Vectors are the same as dynamic arrays with the ability to resize
themselves automatically when an element is inserted or deleted.
Study these functions only:
*The use of these containers and their functions will be explained in the
upcoming weeks
Priority Queue: Priority queues are queues such that the first element
is either the greatest or the smallest of all elements in the queue and
elements are in nonincreasing order.
priority queue.
Math: It contains all the basic Math operations ranging from ceil, and
floor to factorial, pow, etc
Sys: It’s generally used for some specific functions revolving around
the std input and output. Eg: sys.stdin.readline() (which takes input
faster than the normal input function), sys.stdout.flush() (used in
interactive problems) , sys.setrecursionlimit(int) (to increase the
recursion limit) , et
and b .
O(len(list)) .
Try to solve these given problems without using any known algorithms:-
Little Elephan
Hard Calculatio
Who's Opposit
Comma
Additional Questions for practice
Histogram Uglines
Pythagorean Triple
Fraction Floor Su
Cat Cycle
AD-HOC PROBLEMS
Ad hoc problems are those whose algorithms do not fall into standard
categories with well-studied solutions. There are no general techniques to
solve them. They are intuition-based problems, and you may understand
better by solving these:
Teleportatio
Funny Permutatio
Three Door
Exchang
Difference of GCDs