https://code.google.com/codejam/resources/quickstart-guide#gcj


What's the least I need to know to use the competition arena?
There's a lot of important information in the official Terms and FAQ for Kickstart; and if you're competing, you should read them. But if you're on the site to practice your programming skills, or you just need a quick intro to how the competition arena works, here are some steps you can follow:

Open the competition arena to your round. If you're competing, go to your contest's home page at the time of the round. If you're practicing, visit the Past Problems page and select a round. Then select a problem.

Read the problem. The first few sections will describe precisely what problem your program needs to solve. Take careful note of the Limits section. Those limits should help you determine what types of solutions are necessary to handle the Small and Large datasets.

Write a program that will solve the problem, with the Small limits described, in less than 3 minutes or so. Make sure your program accepts input and gives output in the format given; if you run it with the Sample Input as input, it should produce precisely the Sample Output (including the "Case #" text). If you are not sure how to deal with input and output, take a look at the standard I/O tutorial below for one possibility you might like.

At the top of the page, click to solve the Small dataset and download the input file. During a real contest, a 4-minute timer will start as soon as we receive the download request. If you're practicing, there won't be a timer.

Run your program on that input file, and save the result in a file. Submit that file as your output file. (During a real contest, you will also need to submit your source code.) The server will respond in one of a few ways:

Correct: Your submission was completely correct for every case!

Rejected: Your submission was rejected for some reason unrelated to the correctness or incorrectness of your answers. For example, you might have uploaded an input file or source code instead of your own output file. The clock is still running, so see if you can fix the issue before you run out of time (in which case your submission will be treated as Incorrect).

Incorrect: Your result was wrong. We won't tell you which case(s) you got wrong, so you'll have to debug on your own. For a Small dataset, you can fix your program and attempt the dataset again as many times as you'd like. Note that during a real contest, you'll download a new input file for each attempt. If you eventually get the dataset Correct, you will receive a minor time penalty for each incorrect attempt (but it is always better to solve something than not solve it, even with penalties!)

After you solve the Small dataset, the Large dataset will become available. Once your program is ready to deal with the higher limits, download the Large datasets. (It is most common for contestants to write just one solution that solves both datasets.) An 8-minute timer will start as soon as we receive the download request.

Run your program and submit, as with the Small. You won't know whether you solved the problem correctly until the end of the competition. If your submission is Rejected or you want to submit another answer, you can try again within the 8-minute time limit, but only the last submission will be judged.

Move on to another problem (there's a list on the left). Each dataset that you solve correctly is worth a number of points that's written next to its download link. The contestant with the most points at the end of the contest has the highest rank. Ties are broken by which contestant got her last point earliest, with 4 minutes of penalty time added to that for each incorrect submission on a Small dataset that was eventually answered correctly. The scoreboard will display "optimistic" preliminary results for dramatic purposes; that is, it will assume that every Large submission is correct. After the contest, the scoreboard will show the true results, including which Large submissions were wrong.

Tutorials
We only have one tutorial for now, but we may add more in the future. While reading about theory is great, we strongly advise you to practice solving actual problems to get better. You can do so by visiting our Past Problems section. Happy coding!

A "standard" solution: using standard input and output
Kickstart encourages flexible problem-solving: we give you an input file and leave it to you to solve the problem in the way you prefer. It is up to you to choose your language, development environment, architecture, libraries, and so on.

Many of our contestants use a model common in other programming contests like ACM-ICPC and Codeforces: a one-file program that reads the input and produces exactly the required output. This tutorial demonstrates how to use standard input and standard output to apply this model to Kickstart like a pro! Of course, you are still welcome to read input and/or write output in completely different ways; this is just one option.

What are standard input and standard output?
The standard input (stdin) and standard output (stdout) are among the data streams that programs use to interact with the outside world. When you are running a program from the console in the most simple way, stdin is just what is read from the keyboard into the program, and stdout is what is printed on the screen. However, these two streams can be directed to read to, and write from, files!

Suppose that you have a program called "my_program" that you usually run via the command:

MY_PROGRAM
content_copy
 MY_PROGRAM 
Note that MY_PROGRAM could be something like ./my_binary if using a language like C++ that compiles to machine code, java my_java_binary_name for a language like Java that uses virtual machines, or python my_python_code.py for a language like Python that is interpreted rather than compiled.

In Linux, Mac OS/X and Windows, you can use < and > to redirect stdin and stdout to files, respectively. So a command line like

MY_PROGRAM < input_file.txt > output_file.txt 
content_copy
 MY_PROGRAM < input_file.txt > output_file.txt  
will make your program receive the contents of input_file.txt in its stdin, and write the output to its stdout to output_file.txt.

How do I use stdin and stdout for Kickstart?
As you work on a solution, you may wish to read from a file (say, a sample.txt into which you have copied the problem's sample I/O), but still write the output to the console, to avoid having to open or print the output file while you are debugging. You can do this with:

 MY_PROGRAM < sample.txt
content_copy
  MY_PROGRAM < sample.txt 
Once you have downloaded an input, you will want to direct your output to a file to upload:

MY_PROGRAM < small_input.txt > small_output.txt
content_copy
 MY_PROGRAM < small_input.txt > small_output.txt 
If your program's algorithm works for both the Small and Large datasets, you can just rerun this command without even changing nor recompiling the program:

 MY_PROGRAM < large_input.txt > large_output.txt 
content_copy
  MY_PROGRAM < large_input.txt > large_output.txt  
How do I write my code to read from stdin and write to stdout?
Consider the following very simple problem. The input consists of one line with a number of test cases T, and then T more lines, each of which contains two positive integers N and M. The desired output form is Case #x: y z, where x, y, and z are all integers; x is the case number (starting from 1), y is the sum of N and M, and z is the product of N and M.

input_file.txt
content_copy
3
1 5
7 -2
9001 0
 3
1 5
7 -2
9001 0
 
Here's some code to solve this problem, reading from stdin and writing to stdout, in various languages. For our examples, we use some of the most commonly used languages in Kickstart, but you are certainly not limited to using just these!

C++ (commands)
content_copy
g++ solution.cpp -o solution
./solution < input_file.txt > output_file.txt
 g++ solution.cpp -o solution
./solution < input_file.txt > output_file.txt
 
C++ (solution.cpp)
content_copy
#include   // includes cin to read from stdin and cout to write to stdout
using namespace std;  // since cin and cout are both in namespace std, this saves some text
int main() {
  int t, n, m;
  cin >> t;  // read t. cin knows that t is an int, so it reads it as such.
  for (int i = 1; i <= t; ++i) {
    cin >> n >> m;  // read n and then m.
    cout << "Case #" << i << ": " << (n + m) << " " << (n * m) << endl;
    // cout knows that n + m and n * m are ints, and prints them accordingly.
    // It also knows "Case #", ": ", and " " are strings and that endl ends the line.
  }

  return 0;
}
 #include   // includes cin to read from stdin and cout to write to stdout
using namespace std;  // since cin and cout are both in namespace std, this saves some text
int main() {
  int t, n, m;
  cin >> t;  // read t. cin knows that t is an int, so it reads it as such.
  for (int i = 1; i <= t; ++i) {
    cin >> n >> m;  // read n and then m.
    cout << "Case #" << i << ": " << (n + m) << " " << (n * m) << endl;
    // cout knows that n + m and n * m are ints, and prints them accordingly.
    // It also knows "Case #", ": ", and " " are strings and that endl ends the line.
  }

  return 0;

Java (commands)
content_copy
javac Solution.java
java Solution < input_file.txt > output_file.txt
 javac Solution.java
java Solution < input_file.txt > output_file.txt
 
Java (Solution.java)
content_copy
import java.util.*;
import java.io.*;
public class Solution {
  public static void main(String[] args) {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int t = in.nextInt();  // Scanner has functions to read ints, longs, strings, chars, etc.
    for (int i = 1; i <= t; ++i) {
      int n = in.nextInt();
      int m = in.nextInt();
      System.out.println("Case #" + i + ": " + (n + m) + " " + (n * m));
    }
  }
}
 import java.util.*;
import java.io.*;
public class Solution {
  public static void main(String[] args) {
    Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int t = in.nextInt();  // Scanner has functions to read ints, longs, strings, chars, etc.
    for (int i = 1; i <= t; ++i) {
      int n = in.nextInt();
      int m = in.nextInt();
      System.out.println("Case #" + i + ": " + (n + m) + " " + (n * m));
    }
  }

Python 2 (commands)
content_copy
python2 solution.py < input_file.txt > output_file.txt
 python2 solution.py < input_file.txt > output_file.txt
 
Python 2 (solution.py)
content_copy
# raw_input() reads a string with a line of input, stripping the '\n' (newline) at the end.
# This is all you need for most Kickstart problems.
t = int(raw_input())  # read a line with a single integer
for i in xrange(1, t + 1):
  n, m = [int(s) for s in raw_input().split(" ")]  # read a list of integers, 2 in this case
  print "Case #{}: {} {}".format(i, n + m, n * m)
  # check out .format's specification for more formatting options
 # raw_input() reads a string with a line of input, stripping the '\n' (newline) at the end.
# This is all you need for most Kickstart problems.
t = int(raw_input())  # read a line with a single integer
for i in xrange(1, t + 1):
  n, m = [int(s) for s in raw_input().split(" ")]  # read a list of integers, 2 in this case
  print "Case #{}: {} {}".format(i, n + m, n * m)
  # check out .format's specification for more formatting options 
Python 3 (commands)
content_copy
python3 solution.py < input_file.txt > output_file.txt
 python3 solution.py < input_file.txt > output_file.txt
 
Python 3 (solution.py)
content_copy
# input() reads a string with a line of input, stripping the '\n' (newline) at the end.
# This is all you need for most Kickstart problems.
t = int(input())  # read a line with a single integer
for i in range(1, t + 1):
  n, m = [int(s) for s in input().split(" ")]  # read a list of integers, 2 in this case
  print("Case #{}: {} {}".format(i, n + m, n * m))
  # check out .format's specification for more formatting options
 # input() reads a string with a line of input, stripping the '\n' (newline) at the end.
# This is all you need for most Kickstart problems.
t = int(input())  # read a line with a single integer
for i in range(1, t + 1):
  n, m = [int(s) for s in input().split(" ")]  # read a list of integers, 2 in this case
  print("Case #{}: {} {}".format(i, n + m, n * m))
  # check out .format's specification for more formatting options 
As you can see from these examples, most languages provide simple ways of reading from stdin and writing to stdout. This is often easier than referring directly to particular files in your code — you don't need to change or recompile your code when switching from the Small dataset to the Large dataset, or when switching your output destination from the console (for debugging) to a file (so you can submit).

You can always check the documentation of your favorite language to find the preferred way to use stdin and stdout. Almost all languages have one.



+ Recent posts