Abstract
A collection of code templates to kickstart the journey of solving interesting problems on Codeforces!
Tip
- Make sure all inputs are read in in sequence
- Use at least 64Bit to prevent integer overflow issue,
long
in Java,long long
in CPP- Dynamic Array over Array
Java Code Template
Test Solution.java
with test cases inside input.txt
Solution.java
when there are multiple inputs in a single test case
Solution.java
when there is only a single input in a given test case
Basic Data Structure Operation Cheatsheet
Avoid Potential TLE
- If there are many small segments that need to be printed out one by one, or we need to consolidate many small input string pieces into one string. Consolidate them into one string with
StringBuilder
. Because string in java is Immutability, concatenating 2 strings require us to create a new string. Example: without StringBuilder Buffer, with StringBuilder Buffer- Use
BufferedReader
,InputStreamReader
andStringTokenizer
to read in the input, instead of usingScanner
CPP Code Template
Test Solution.cpp
with test cases inside input.txt
Solution.cpp
when there are multiple inputs in a single test case
Solution.cpp
when there is only a single input in a given test case