According to USACO rules:
You may… NOT use pre-written code or “templates” to get a head start on your coding, and you may not consult resources other than those that provide information about basic functionality of your programming language
My main question is about the “pre-written code or ‘templates’” section. The rules themselves don’t define either of these, so I have some concerns on what will and won’t be flagged.
For example, when implementing binary search, I write this Java code:
static int binarySearch() {
int ans = SOME_DEFAULT_VAL;
int l = 0;
int r = SOME_MAX_VAL - 1;
while (l <= r) {
int mid = l + (r - l) / 2;
if (check(mid)) {
ans = mid;
r = mid - 1;
} else l = mid + 1;
}
return ans;
}
static boolean check(int RELEVANT_VARIABLE_NAME) {
// arbitrary code
return SOME_BOOLEAN_VALUE;
}
I’ve memorized this “template” as I’ve done more and more binary search problems, and tend to keep the variable names the same as a result. This template isn’t my own, either; I heavily based it off of the USACO guide and decided to use it as it keeps everything well-organized and helps with debugging. Obviously I’m not looking at the USACO guide when implementing this, but I’m not sure if I will be flagged if I use this every single time I do a binary search.
So,
- Can I be flagged/banned for using this code (written from memory, of course) in a contest? If so,
- How do I change this algorithm to avoid breaking USACO rules?
Related Questions:
These questions are all similar to mine, but I don’t feel like any of them apply sufficiently to my issue. Maybe the last one, but the USACO guide specifically says that
you should not refer to [Kattio] during a USACO contest
so I’m still a bit wary.
Thank you.