Competitve Programming
Competitve Programming
Prog.
Language CP Maths
Data
Structures
Benefits for teachers
• Make programming classes more interesting
• Example 1, Example 2
• Use online judges for evaluation
• Be a PROUD teacher – how?
– Make them compete in Olympiads
– Bring laurels to your school
– Inspire the next generation
• Online judges even prevents plagiarism
What is a problem set?
A problem statement typically explained with a
story line. Eg:
Hari and Class Marks
Hari is a multi-talented person, and prepares
results for his college in his free time. (Yes,
he is still in love with his old college!) He
gets a list of students with their marks. The
maximum marks which can be obtained in the exam
is 100.
Hari is supposed to arrange the list in such
that student with highest mark appears first.
And if two students have the same marks, they
should be arranged in lexicographical manner.
Help Hari prepare to the same!
Components in a problem set
• Problem Statement
• Constraints
– Limitation on the input / output values
– Specific data type to be used
• Input Values
• Expected Output
• Input Format
• Output format
• Test Cases
Components in detail….
• Constraints
– Limitation on the input / output values
– Specific data type to be used
In a program where the number of students
can’t be more than 100.
Decimal values not more than two
No negative values allowed
Length of name
Components in a problem set
• Input Values
3
Eve 78
Bob 99
Alice 78
• Expected Output
Bob 99
Alice 78
Eve 78
Components in a problem set
• Input format:
On the first line of the standard input,
there is an integer N, denoting the number
of students. N lines follow, which contain
a string and an integer, denoting the name
of the student and his marks.
• Output format:
You must print the required list.
Important..
• Collection of expected input and corresponding
output
• It can by of any type of value
• Number of test cases increases based on the
complexity of the problem statement
• Some test cases may succeed and some may
fail
• Success means program has to pass all test
cases
What is an online judge?
• Program that evaluates your source code
• Compiles & executes online
• Verifies the correctness
• Tells you whether your program passed all the
test cases
• Tells you whether your program passed the
time constraint
• Tells you whether your program passed the
memory constraint
Possible Results
Accepted Your program ran successfully and gave a correct
answer. If there is a score for the problem, this will be displayed
in parenthesis next to the checkmark.
Time Limit Exceeded Your program was compiled successfully,
but it didn't stop before time limit. Try optimizing your approach.
Wrong Answer Your program compiled and ran successfully but
the output did not match the expected output.
Runtime Error Your code compiled and ran but encountered an
error. The most common reasons are using too much memory or
dividing by zero. For the specific error codes see the help section.
Compilation Error Your code was unable to compile. When you
see this icon, click on it for more information.
How to start practicing?
• Register in any online judge
• Read the problem set
• Understand the input values carefully
• Understand expected output and its format
• Try solving in the local computer
• Give input values
• See the output values
• Submit in the online judge
• Most online judges are in Unix. So, use
CodeBlocks IDE
1. Register in CodeChef
2. Go to Practice->Beginner
3. Scroll down
4. Chose the problem with maximum submissions
5. Read the problem statement and start solving
with pen and paper
6. Write the code in the editor – Any language
7. Submit -> Debug if needed
8. Read the editorial if there is any doubt
9. Editorial
Why wait?
Start Coding!
Thank You!