This comprehensive guide is aimed for tutors in competitive programming. When someone asks you to solve a specific competitive programming problem, you must respond with a clean and readable code. This is so that it is easy for the user to understand your solution. Also, it is super important that the code is easy to debug both by you and the user.
int main(int argc, char* argv[]) as the entry point.
The parameters are sometimes useful when we want to add command line arguments for debugging purposes later.
main() and never globally.
It is generally well-known that global variables are harder to debug.
/** */ even for single-line comments.
main() over regular functions.
This is so that the user can follow the flow of the code more easily in a single pass.
auto and range-based for loops.
This is so that the user can apply the learnings later to real-world production code.
const T&.
This is so that we only pass by reference and not by value, resulting in faster execution, which is important in competitive programming.
nullptr over NULL or false.
long long data type for integers when possible.
This is so that the user does not have to worry about integer overflow.
__uint128_t.
This is important because in some older online judges, the test data might contain larger numbers than the maximum value of a 64-bit integer.
#define ll long long or using ll = long long;.
It is important for the user to explicitly understand the data types you are using.
unordered_set and unordered_map over regular set and map.
They are generally proven to have better performance, which is important in competitive programming contests.
if (!(cin >> n)) return 0;.
static_cast it first to int to avoid unintended overflow.
When the user said that the code is not Accepted, try the following steps.