Dissecting a problem statement

Each question you read will present a different interesting problem for you to solve. Each problem consists of a few common parts:

  1. The statement - This part explains the problem, usually with a nice story to go with it. Read through this carefully. It will introduce and explain the relevant parameters to the problem, and what your program must calculate. The exact input/output format are left for the sections below.
  2. Input Format - Describes how your program should read the input (the order of variables, what lines they are on etc.).
  3. Output Format - Describes how your program should print the output.
  4. Input/Output files - The files that your program should read from and write to.
  5. Time and Memory limits - When you submit your code, it will be run on secret test cases to determine whether it is correct. The time limit is the maximum amount of time that your code can use per test case. The memory limit is the maximum amount of memory that your code can use per test case.
  6. Sample cases - Some example inputs and outputs for the problem. These are provided, sometimes with an explanation, to help you understand the problem statement. Read through these carefully, as they might help clarify some some of the trickier aspects of the problem. You can also use these to test your code -- but be careful, the sample cases are usually very basic and very small. Just because your code passes the sample cases, doesn't mean that your code is correct!
  7. Constraints - This section describes how large the inputs will be in the worst case. This is usually a lot larger than the sample cases, so read this section carefully!
  8. Subtasks - Even if you don't have an idea for solving the full problem, subtasks give you the opportunity to score a substantial portion of the full points for simpler variants of the problem. In this way, you can score points for correct algorithms that aren't completely efficient, or score points for coming up with a correct algorithm for a simpler variant of the problem. On ORAC (and in the AIO), you must solve every test case within a subtask to score points for that subtask. See the About page for more information on how submissions are judged and scored.
Depending on the year they came from the order of these sections might be different, or some sections will be merged, but every problem will have these.

Let's look at Vases from AIO 2019 as an exaple. See if you can spot all the sections described above. Then give the problem a shot! There are some templates provided below to help you get started. Feel free to use them if you're not comfortable with reading/writing files. Click on the hint if you're stuck coming up with a solution.

Put 1 flower in the first vase, 2 flowers in the second vase and the rest in the third vase. This works for almost every value of N, but starts to fall apart when N is too small. This will score 85 points if coded correctly. Can you figure out what happens when N is too small? What do you do in that case?

/*
 * Solution Template for Vases
 *
 * Australian Informatics Olympiad 2019
 *
 * This file is provided to assist with reading and writing of the input
 * files for the problem. You may modify this file however you wish, or
 * you may choose not to use this file at all.
 */

#include <cstdio>

/* N is the number of flowers. */
int N;
int a;
int b;
int c;

int main(void) {
    /* Open the input and output files. */
    FILE *input_file = fopen("vasesin.txt", "r");
    FILE *output_file = fopen("vasesout.txt", "w");

    /* Read the value of N from the input file.  */
    fscanf(input_file, "%d", &N);

    /*
     * TODO: This is where you should compute your solution. Store the number
     * of flowers that should go in the first, second and third jars in the
     * variables a, b and c. If it is impossible to arrange the flowers
     * according to the rules, set each of these variables to 0.
     */

    /* Write the answer to the output file. */
    fprintf(output_file, "%d %d %d\n", a, b, c);

    /* Finally, close the input/output files. */
    fclose(input_file);
    fclose(output_file);

    return 0;
}
import sys
sys.setrecursionlimit(1000000000)

#
# Solution Template for Vases
#
# Australian Informatics Olympiad 2019
#
# This file is provided to assist with reading and writing of the input
# files for the problem. You may modify this file however you wish, or
# you may choose not to use this file at all.
#

# N is the number of flowers.
N = None
a = None
b = None
c = None

# Open the input and output files.
input_file = open("vasesin.txt", "r")
output_file = open("vasesout.txt", "w")

# Read the value of N from the input file.
N = int(input_file.readline().strip())

# TODO: This is where you should compute your solution. Store the number of
# flowers that should go in the first, second and third jars in the variables
# a, b and c. If it is impossible to arrange the flowers according to the
# rules, set each of these variables to 0.

# Write the answer to the output file.
output_file.write("%d %d %d\n" % (a, b, c))

# Finally, close the input/output files.
input_file.close()
output_file.close()

Click here to go back.