Ways of Proceeding and Honor Code

Holding eliminations rounds online is the most feasible setup we can do this year for a national programming competition for high school students. This setup is convenient for you, the participants, as you can code at the comfort of your own school – or even at your own home!

To keep everything as fair as possible, we trust that all participants and coaches read through and follow the honor code below during the online elimination rounds:

The Four Codemandments

I.
The first rule of reading NOI problems
is you do not talk about the NOI problems

(until after the round is concluded)

You are not allowed to discuss the problems with anyone else until after an hour after the contest. This includes talking to your co-participants in-person or online. Moreover, posting the problems on forums (such as but not limited to Quora, etc) during the contest is not allowed. Co-participants, coaches, parents, siblings, guardian angels, and friends may stay with you for moral and technical support (i.e. setting up the computer), but offering and receiving help in solving the problems is strictly prohibited.

II.
Any code submitted to the contest
must have been written by you

All parts of the code you submitted must have been written by you, the participant. Snippets of codes you have written in the past may be used during the contest itself. Codes from other people including but not limited to friends, co-participants, and strangers from the Internet are not allowed. Suspicious code, as has been done in the past, will be investigated.

III.
Questions regarding the problems are to be raised
at the discussion panel of the problem

Questions specific to the problems involved should be written in the discussion panel of the problem for everyone to see. This means that all correspondence between the NOI Scientific Committee regarding the problems are public and available to all. You could also check your notifications and the discussion pages of the problems should the need arise for clarifications. For technical support, you may consult ask[at]noi.ph preferably before the contest starts.

IV.
Consulting the internet is fine.

As this is an online competition, it is nearly impossible to ban participants from consulting the Internet for help with the problems. Moreover, it might even lose you time if you only start reading on the duration of the contest itself. So we suggest you prepare before the contest starts. Furthermore, we would like to reiterate that from the second codemandment, you are not allowed to copy-paste any code found on the internet. We advise not to use it too much though, as in the Finals Round, using the Internet for purposes other than HackerRank is prohibited.

Penalties

NOI.PH is an official event of the Philippines sanctioned by the government of the Republic. The consequences of violating any of the aforementioned commandments are at least the following:

  1. Immediate disqualification from the whole competition.
  2. Cases of dishonesty will be reported to government agencies including, but not limited to, the DOST, ICTO, and DepEd.

Conclusion

Now that you’ve read the honor code, you should familiarize yourself with the official rules. Only officially participants who register before the deadline will be allowed to join the contest. Moreover, if you haven’t already, you can also consult the Frequently Asked Questions page. For other concerns, contact us by emailing [email protected]. If you have no more concerns, open your favorite text editor and start practicing!

Submitting Your First NOI Program

After reading the problem and taking note of the important details, you should start thinking how to solve a problem.

Once you think you have an answer, start coding! NOI allows the programming languages C, C++, Java and Python. You can choose your language by using the code editor.

Programming language switcher. On the upper-right hand side of the code editor, you can choose the programming language you wish to use.
Programming language switcher. On the upper-right hand side of the code editor, you can choose the programming language you wish to use.

For this post, we will solve the problem entitled Aguinaldo (pdf version) and use Java. If you can’t access the problem, you should try signing up for HackerRank first and following the instructions on this post.

Attempt #1

Before we begin, read the problem first and try to think of a solution. Are you done? Let’s begin. Here is our first attempt at this problem.

Looking at the code, do you think this will print the correct answer? Let’s submit it and see what happens.

Oh no! We got a wrong answer, even for the sample test file! We were very careless.
Oh no! We got a wrong answer, even for the sample test file! We were very careless.

We can actually press the Run Code button first to see how our code fares with the sample input. Pressing the Run Code button gives us this:

Sample input. Running our code with the sample input, we can clearly see where we went wrong in that specific case.
Sample input. Running our code with the sample input, we can clearly see where we went wrong in that specific case.

Attempt #2

Just like Jason Mraz, we wont give up! We can see from the disaster that is Attempt #1 that we forgot to take note of the output format. Now, rewriting line 22 as:

We submit again and obtain…

Attempt #2. We have the first test file down, but the second test file is stubborn! Let's investigate.
Attempt #2. We have the first test file down, but the second subtask is stubborn! Let’s investigate.

The reason why this is a wrong answer is not trivial. Where are we going wrong? Let’s look at the judges’ input to see what’s happening.

Attention! Normally, it wouldn’t be possible to look at the judges’ input. You’ll have to try your own test cases based on the constraints to see why you’re getting a wrong answer. You normally need to be creative enough to figure out which large cases your program fails at.

Custom input. Let's try to run our program to the judges' first test case.
Custom input. Let’s try to run our program to the judges’ first test case.

You get an error. Can you try fixing the code before reading the next section?

Attempt #3

If you were keen enough, you would have figured out that to fix the error, we should have taken long as input, as opposed to int. This could have been avoided if we carefully looked at the constraints. A Java int would have a maximum value of 2147483647 before overflowing. This is less than 2149599350, the first value of N in the judges’ input. Sneaky judges! Let’s fix our code once again!

We need to get rid of an array since allocating space for more than 2147483647 ints will be too much! We should realize that all array elements assign the same value P. Let’s throw away the array and just add P again and again until we’ve done it N times. This should be correct now.

…and submit!

Terminated due to timeout. Our program runs too slowly!
Terminated due to timeout. Our program runs too slowly!

We have exceeded the time limit of 4 seconds (for Java)! That means our algorithm runs very slowly. Perhaps there is something we’re doing inefficiently? Maybe we’re making our program compute unnecessary operations? What could it be?

Final Attempt

Now, after using pen and paper to figure out how to rewrite my program to make it more efficient, here’s my program to solve the problem correctly and quickly. Here’s the code!

If it doesn’t show up properly in your browser, don’t worry! You’re smart enough to figure it out for yourself!

How to Access the NOI Practice Problems

Here’s how to access the NOI Practice Problems.

  1. Sign yourself up for a HackerRank account.
  2. Login with your credentials.
  3. Register yourself to the NOI Practice Contest.

IOI 2016 will be held in Kazan, Russia. Join NOI.PH 2016 to qualify!

The beautiful city of Kazan in Russia is host to the 2016 International Olympiad in Informatics. To have the chance to represent the Philippines at the 2016 IOI, register and join the NOI.PH 2016!