Programming Contest - Frequently Asked Questions
General Questions
- What is the ACM ICPC?
- What is the BU ACM Chapter programming contest?
- Why should I care?
- What types of programs need to be written to solve the problems? What languages are supported?
- What kind of problems are given? Where can I find sample problems?
- Are competitors allowed to bring code or other materials with them to the contest?
- What type of environment is the BU ACM chapter programming contest held in?
- How are team contests structured?
Questions about input and output
- How does the program get input and where does the program place output?
- What is “redirection”? How do I redirect input and output?
- Why are STDIN and STDOUT used for input and output? Why not use function parameters and return values (like TopCoder)?
- What does a simple “hello world” application look like in C++ and Java?
- How do a read all of the input line by line in C++ or Java?
- Once I have read a line from STDIN, how to a read the line word by word in C++ and Java?
- How do a convert a string to a number and how do I convert a number to a string?
Questions about submitting solutions and the scoreboard
- What is the scoreboard?
- How do I submit a solution to a problem?
- How do I check on the status of my last submission?
- How do I read the scoreboard? How can I tell if I got credit for a problem?
- What if my code contains an infinite loop?
- My code compiles fine, but then when I submit it the scoreboard reports back that there was a compiler error. How is this possible?
- My code runs fine when I test it on my machine, but when I submit it the scoreboard reports back that the program crashed. Why is this happening?
- My code runs fine when I test it on my machine, but when I submit it the scoreboard reports back that the program was terminated due to a security violation. What are security exceptions?
- What are the possible responses I can get back when I submit a solution to a problem?
- My program appears to produce the correct answer when I test it, so why is it being rejected when I submit it?
- After a contest is over, can I see the testcases and the solutions? Can I get a copy of the code I submitted during the contest?
Organizational Questions
- Where does the prize money come from?
- Who is eligible for prizes?
- Who administers the BU ACM programming contests?
- Who developed the scoreboard?
- How did BU ACM chapter start?
- I am interested in sponsoring or co-hosting a BU ACM chapter contest. Who should I contact?
General Questions
What is the ACM ICPC?
The ACM (Association for Computing Machinery) hosts the ICPC (Intercollegiate Programming Contest) where schools across the world compete against each other. Each school sends a team of 3 students. At the start of the contest, between 6 and 9 problem statements are given to the teams. Each team gets one computer to work on. They must write programs that solve the problems, and submit them to the judges, usually via email. The teams are usually given 5-6 hours to solve the problems. Teams are ranked in terms of number of problems solved. If two teams solved the same number of problems, then they are ranked according to submission times. If you are interested in finding out more about the ACM Intercollegiate Programming Contest, the main website is at: http://icpc.baylor.edu/icpc/. Also, the ACM ICPC Northeast North America region website is at: http://www.cs.rit.edu/~icpc/.
What is the BU ACM Chapter programming contest?
The newly formed Binghamton University chapter of the ACM has decided to host several contests during this semester (Spring 2006) and hopefully future semesters as well. We have modeled our contests after the ACM ICPC, with a few changes for practical purposes. Our contests usually last about 2 hours, we usually give 5-7 problems, and we use an automated system to check submissions for correctness. Also, BU ACM Chapter programming contests are individual competitions, not team competitions.
Why should I care?
The ACM ICPC is a fun way to sharpen your skills at programming, get noticed by IBM (who sponsors the ICPC) and other companies, bring glory to yourself and your school, and meet other people who have a passion for algorithms, problem solving, and programming. One of the purposes of the BU ACM chapter programming contests is to make students aware of and interested in the ACM ICPC (and prepare them to compete). Also, BU ACM chapter hopes that its contests will provide a way for students to make a name for themselves among their peers and within the Watson CS department, and also a way to beef up their resume and get noticed by employers. Several companies are already interested in our contests, including Microsoft and Bloomberg. All of those reasons aside, the contest offers cash and other prizes, and there are usually small door prizes for everyone who competes as well.
What types of programs need to be written to solve the problems? What languages are supported?
The problems are to be solved by writing a console application (not a GUI application). The contest focuses on algorithms, and as such solutions to problems never involve the use of threads, GUIs, sockets, or the file system. Currently, only C, C++, and Java are supported. However, plans are underway to add support for C#.
What kind of problems are given? Where can I find sample problems?
Some problems are based on number theory or geometry. Other problems involve combinatorics and graph theory. Yet other problems have no "textbook" solution, and simply need to be solved using brute force methods. The contests section contains problems from past contests as well as links to other sites containing old ACM problems.
Are competitors allowed to bring code or other materials with them to the contest?
Competitors are allowed to bring in books or any other printed materials to the contest, however they are not allowed to bring in disks, CDs, or any other electronic materials.
What type of environment is the BU ACM chapter programming contest held in?
For the Spring 2006 semester we have reserved room G04 in the Academic A building. The computers in this room, like most computers on campus, use Microsoft Windows. The computers have Microsoft Visual C++ 6, Java 1.4, BlueJ, and Eclipse installed on them. If one desires a linux/UNIX style environment, cygwin is available. Also, one can telnet into the bingsuns server for a UNIX environment.
How are team contests structured?
Team contests occur in the same timeframe as our usual contests. Teams are made of three students and they register one account for their team. There are generally 3-5 questions and prizes are awarded to each team member. Team competition prizes do not have the same first place restriction as our normal contests. Questions in this format may have multiple valid answers and therefore answers require verification by the server - this may take additional time and be applied to your timeout period (the verifier will be compiled using -O3 to reduce this effect as much as possible). Teams will only be allowed to use one computer during the competition.
Questions about input and output
How does the program get input and where does the program place output?
Input is provided through STDIN (cin in C++, System.in in Java). Output is to be written to STDOUT (cout in C++, System.out in Java). Since STDIN is simply a stream of ASCII characters, all input will always be provided in “string” form. Part of the challenge of the ACM contest is parsing input. Thus, it is important to know how to read lines from STDIN. It is also important to know how to do redirection from the command line using the “<” and “>” characters.
Output written to STDOUT must have the exact format that the problem asks for. Thus, if you have debug messages that print additional information to the screen in your code, make sure you comment out these lines before you submit your solution. Any extra information in the output will be considered “incorrect output”, and the submission will not get credit.
What is “redirection”? How do I redirect input and output?
In Windows, Linux, and UNIX, the user can “redirect” STDIN and STDOUT when running a program from the command line. Traditionally, when a program reads STDIN, the keyboard is read. However, one can redirect STDIN so that a program instead reads from a file. Suppose that “prob1” was a program and “input.txt” was a file, then we can run “prob1” and redirect STDIN with “input.txt” by typing “prob1 < input.txt” at the command line. Thus, the contents of input.txt will be fed to prob1 as if it was input from the keyboard. When the end of the file is reached, future calls to read STDIN will fail.
Traditionally, when a program writes to STDOUT, the data is printed to the screen. However, output can also be redirected to a file. Again, suppose “prob1” was a program and “output.txt” was where you wanted the output to be stored, then we can run “prob1” and redirect STDOUT with “output.txt” by typing “prob1 > output.txt” at the command line. Thus, the data that the program writes to STDOUT will be recorded in “output.txt”. Input and output direction can be used together. Thus, typing “prob1 < input.txt > output.txt” will run “prob1”, feeding it the contents of “input.txt” through STDIN, and recording what it writes to STDOUT in “output.txt”.
Using input redirection is highly recommended for the ACM contest. It saves the competitor the hassle of constantly retyping test inputs. Output redirection can also be useful as it also allows the user to keep a record of the output.
Why are STDIN and STDOUT used for input and output? Why not user function parameters and return values (like TopCoder)?
As stated before, the BU ACM chapter programming contest is based on the ACM ICPC. For at least the last ten years, ACM ICPC has used STDIN and STDOUT for input and output. The choice to use STDIN and STDOUT was probably a matter of convenience for administering contests. If inputs were to be provided as parameters, ala TopCoder, then a competitor would not be writing a main() function, but rather he would be writing a function that plugs into a larger program (this is what TopCoder does). Thus, this complicates the matter of students running and testing their own code, since they would need a mechanism that would plug their function into the larger program and run it whenever they wanted to try out their code. ACM ICPC still uses STDIN and STDOUT for input and output. As BU ACM Chapter seeks to imitate the ICPC, we have also chosen to use STDIN and STDOUT for input and output. Parsing input is a small part of the challenge of the contest, and, with a little practice, one can become very good at quickly writing code that parses input from STDIN. To get better at parsing input, see the code below for reading input a line at a time, and see the code for reading a line one word at a time, and read up on the stringstream and StringTokenizer classes. Also, check out the solutions to the problems from the 2/9/2006 contest. These solutions provide good examples of how to read lines and words in C++.
What does a simple “hello world” application look like in C++ and Java?
// ----------------------------------------------
// C++
// ----------------------------------------------
#include <iostream>
using namespace std;
//Don’t forget to make main() return int
int main()
{
cout << “Hello from C++\n”;
//Don’t forget to return a value
return 0;
}
// ----------------------------------------------
// Java
// ----------------------------------------------
import java.io.*;
// Don’t forget to make the class public
public class Problem1
{
//Don’t forget to make main() public and static
static public void main(String args[])
{
System.out.println(“Hello from Java”);
}
}
How do a read all of the input line by line in C++ or Java?
// ----------------------------------------------
// C++
// ----------------------------------------------
#include <iostream>
using namespace std;
int main()
{
vector<string> lines;
string str;
for (getline(cin,str); cin.good(); getline(cin,str))
lines.push_back(str);
return 0;
}
// ----------------------------------------------
// Java
// ----------------------------------------------
import java.io.*;
public class Problem1
{
static public void main(String args[])
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Vector lines = new Vector();
String str = in.readLine();
for (; str != null; str = in.readLine())
lines.add(str);
}
}
Note that the code given above will never terminate if STDIN is not redirected with a file. The loops in the code above break when the end of file is reached. If input is not redirected and the keyboard is used, EOF will never be reached (since the keyboard is treated as a never-ending file), and so the loops will never break. This is yet another reason why it is highly recommended to use input redirection when testing your code.
Once I have read a line from STDIN, how to a read the line word by word in C++ and Java?
// ----------------------------------------------
// C++
// ----------------------------------------------
#include <iostream>
#include <sstream> //need for stringstream
using namespace std;
int main()
{
vector<string> words;
string line, str;
if (getline(cin,line))
{
stringstream ss(line);
while (ss >> str)
words.push_back(str);
}
return 0;
}
// ----------------------------------------------
// Java
// ----------------------------------------------
import java.io.*;
import java.util.*; //needed for StringTokenizer
public class Problem1
{
static public void main(String args[])
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
Vector words = new Vector();
String line = in.readLine();
if (line != null)
{
StringTokenizer st = new StringTokenizer(line);
while (st.hasMoreTokens())
words.add(st.nextToken());
}
}
}
How do a convert a string to a number and how do I convert a number to a string?
// ----------------------------------------------
// C++
// ----------------------------------------------
#include <iostream>
#include <sstream> //need for stringstream
using namespace std;
int main()
{
int k = 3;
string numStr = “-40”;
//Convert k, an int, to a kStr, a string
stringstream ss;
ss << k;
string kStr = ss.str();
//Convert numStr, a string, to num, an int
stringstream ss2(numStr);
int num;
if (!(ss2 >> num))
cout << “Error: numStr is not an integer\n”;
return 0;
}
// ----------------------------------------------
// Java
// ----------------------------------------------
import java.io.*;
public class Problem1
{
static public void main(String args[])
{
int k = 3;
String numStr = “-40”;
//Convert k, an int, to a kStr, a string
String kStr = Integer.toString(k);
//Convert numStr, a string, to num, an int
int num = 0;
try {
num = Integer.parseInt(numStr);
} catch (NumberFormatException nfe) {
System.out.println(“Error: numStr is not an integer\n”);
}
}
}
Questions about submitting solutions and the scoreboard
What is the scoreboard?
After you register and are assigned a user ID, you are taken to the “scoreboard” web page. The scoreboard displays the current contest standings. The scoreboard also has a form that allows you to submit solutions, and the scoreboard displays information about your latest submission. You should leave the scoreboard open during the entire contest, as you will need it to submit solutions and check to see if they are accepted.
How do I submit a solution to a problem?
There is a form at the bottom of the scoreboard page. Specify which problem you are submitting a solution to, specify which language you used, and specify the location of your code. Then click the “Submit” button and your code will be sent to our server.
How do I check on the status of my last submission?
The scoreboard will display the status of your latest submission when our server finishes compiling it and testing it. The scoreboard page automatically refreshes every 15 seconds or so, and you can manually refresh it by clicking the “Reload” button in the web browser.
How do I read the scoreboard? How can I tell if I got credit for a problem?
The scoreboard contains a row for each competitor, and two columns, “time” and “attempts” for each problem. The competitors are sorted by rank. The “time” field displays the time that the first correct solution to the particular problem was submitted. The “attempts” field displays the number of times a solution has been submitted for the particular problem. If a correct solution to a problem has not yet been submitted, “-“ is displayed in the “time” field. Thus, if you submit a solution to a problem, and several minutes later “-“ is still displayed in the “time” field, then that means your solution was not correct. If a time is displayed in the “time” field, then that means your solution was accepted.
What if my code contains an infinite loop?
Our server will only allow your program to run for 30 seconds. If after 30 seconds the program has not finished running, it is killed, and the solution is rejected. When this occurs, your solution is said to have “timed out”.
My code compiles fine, but then when I submit it the scoreboard reports back that there was a compiler error. How is this possible?
Unfortunately, our server runs on Linux and uses g++ and gcc, while the computers that competitors use are Windows machines. Microsoft’s Visual C++ compiler does not completely adhere to the C++ standard, and so there are instances where C/C++ code will compile successfully on MSVC but not gcc and g++. Luckily, this occurs relatively infrequently. However, when the scoreboard reports a compile error, it will display the line number and the type of error to help you fix the problem. The likelihood of this occurring can be reduced by using cygwin or telnetting into bingsuns and using gcc and g++, or simply by using Java.
My code runs fine when I test it on my machine, but when I submit it the scoreboard reports back that the program crashed. Why is this happening?
Some C/C++ programs will run fine on one architecture but will crash on another architecture. The most common case of this occurs in C when casting creates alignment problems. As long as you don’t cast one pointer to a different kind of pointer this problem should not arise. Another common case is when a variable is not initialized or a function that should return value is missing a “return” statement. On some architectures the uninitialized variables might be set to 0 and no noticeable error occurs, while on other architectures the uninitialized variables are set to some large number that causes an access outside the bounds of an array.
My code runs fine when I test it on my machine, but when I submit it the scoreboard reports back that the program was terminated due to a security violation. What are security exceptions?
A security exception will occur if your code attempts to access the file system, open a socket, or make certain system calls. Obviously, this can be avoided by simply not attempting to read from files, write to files, delete files, open sockets, or make system calls.
What are the possible responses I can get back when I submit a solution to a problem?
There are six possible responses: 1) your code had a compile error, 2) your code compiled but it crashed, 3) your code ran but it timed out, 4) your code ran and was terminated due to a security exception, 5) your code ran but it did not produce the correct output, and 6) you solution was accepted.
My program appears to produce the correct answer when I test it, so why is it being rejected when I submit it?
Our server tests your submitted solution using many test inputs other than the sample inputs provided in the problem statement. Therefore, it is very possible that your program produces the correct answer for the sample inputs but does not produce the correct answer for some other particular input. Part of the challenge of the ACM contest is that you need to think of your own testcases. The sample inputs are provided to clarify the problem statement and demonstrate certain special cases; however, sample inputs usually do not demonstrate all special cases. For example, the problem statement for Problem 1 in the 2/9/2006 contest, “Finishing the Square”, provided a sample input where both missing values occur in the same column. However, the problem statement did not provide an additional sample input where both missing values occur in the same row. Thus, it is highly recommended that you try coming up with other inputs in addition to the sample inputs provided.
We have mechanisms that allow us to see why a solution is being rejected, and we can also manually test submitted solutions. We will be monitoring submissions manually throughout the contest to make sure that correct solutions are not being rejected by the testing system, and also that incorrect solutions are not being accepted.
After a contest is over, can I see the testcases and the solutions? Can I get a copy of the code I submitted during the contest?
Yes and yes. After a contest is over, the problem statements, the testcases, and the solutions will be posted on the BU ACM chapter webpage. All of the code that was submitted during the contest will also be posted.
Organizational Questions
Where does the prize money come from?
Each contest is sponsored by individuals outside the BU ACM chapter or by a business or organization. The sponsors provide the cash prizes and other prizes for the contest. For example, the 2/9/2006 contest was sponsored by Prof. Madden and Prof. Garrison, and the 3/9/2006 contest was sponsored by Microsoft.
Who is eligible for prizes?
To be eligible for prizes, you must be a BU student. The students on the contest committee and the students who competed in the most recent ACM ICPC Regional competition are not eligible for cash prizes. There are currently no rules preventing a student from winning cash prizes in several consecutive contests. However, we limit first place prizes to once per school year.
Who administers the BU ACM programming contests?
Typically contests are administered by the contest committee. However in some cases sponsors may provide their own personnel to administer the contest (ex. TopCoder).
Who developed the scoreboard?
The scoreboard was developed by BU ACM Chapter members Natan Zohar and Daniel Benamy.
How did BU ACM chapter start?
Since 2001, under the initiative of Prof. Madden, Binghamton University has sent three person teams to compete in the ACM ICPC. From 2001 to 2005, BU has made it to regionals almost every year. Over the years, the student coach and a few of the students who competed gradually became more serious about the contest. The students began to assume the responsibilities of actively recruiting students for the Binghamton team, making the necessary travel plans, and filling out the paperwork. In fall of 2005, Binghamton’s team placed second at regionals, earning an invitation to the world finals. At this point the CS department and others became very interested in the Binghamton team and the ACM ICPC. The students used this momentum to form the BU ACM chapter, an SA chartered group, in spring of 2006.
I am interested in sponsoring or co-hosting a BU ACM chapter contest. Who should I contact?
You should contact the contest committee chair at: andrew.paroski@binghamton.edu