Silly mistakes are like syntax errors. They can cause your entire program to become useless. Pity that there is no compiler for detecting them.
So whats the silliest mistake you have ever done in a contest problem ? And when you realized it later, you had that "WTF was I thinking then" kind of feeling.
Yesterday while doing div 2 B, I was pretty confident that my approach was correct, but kept failing a pretest.
I couldnt sleep properly due to that mistake, so I woke up at 3am and found this stupid silly mistake.
Not something I personally did, but on a TC today I saw someone whose solution failed during the challenge phase because they modded by
10e9 + 7
instead of1e9 + 7
. Whoops.And now, with this morning's contest, I am myself guilty of a similar crime on this problem. -.-
(Why was the mod 109 + 9 on that problem, but 109 + 7 on all of the others?)
Three years down the lane, still relevant!
6 years down the lane still revelent
this except with the Zashikhin prime
In a CF round I got RE because I must change 100 to 500! I don't want to think about that :(
Forget to print the answer modulo some number :D
my silliest mistake was in APIO 2013 the problem robots , I spent a lot of my time debugging my solution without any success, after the contest I discovered that the obstacles in the input is 'x' (small one) while I was thinking it was 'X' (capital), I lost a bronze medal because of it :(
I used maxn = 501 instead of maxn = 5010 in COCI contest and got 42 points instead of 140.
Factorizing 9: I wrote 9 = 3*3*3
:/
I have a similar mistake...
6!=5!*3!*2!
9!=7!*(2!)^3*(3!)^2
In Codeforces Round #292 Div. 1 Problem A :(
And I used set<pair<int,int> > to solve Problem B and got TLE in system tests :(
I locked my problem without checking it properly, and hello div.2
You can hack yourself in this case
NEERC ACM quarterfinal. There was two variables with the same name:
-Wshadow is your friend
Same as you. It took about three hours to debug :|
I used an array of size 111*111 instead of 1111*1111 in div2 A problem and it was hacked in the last few seconds of the contest :/
I once coded an offline solution for yet another problem "answer Q queries" and forgot to sort queries by index before printing the answer. I was debugging it for about 40 minutes. The entire code was correct except this missing sort. Of course, I used only one test case during debugging executions, so answer was correct every time.
Forget to take absolute value sm = (a+b)-1 instead of sm = abs((a+b)-1), I found my mistake after I locked the problem
Yesterday in problem B I read numbers r and g and then r numbers and then g numbers. While I should read r and then r numbers, then g and g numbers...
Now this case came in my mind. Three years ago in a Bulgarian competition one of the task was to print some triangles or rectangles with '*'. I solved it and then I got 0 points. I decided to test my solution myself and I saw that I have forgotten to put whitespace between the symbols and this cost me the second place :D
Using int when long long was required.
Getting overflow even when using long long. For example to check if a's sign and b's sign is different by multiplying them and comparing with -1.
Using wrong initial values for max(0 when maximum element could be negative) or min variables(INT_MAX instead of 1e18).
While copy pasting query and update function calls of segment trees, forgetting to change arguments.
Wrongly inserting intial elements in a vector. push_back(some value) twice instead of just once.
while(scanf("%d",&a)!=EOF) instead of while(scanf("%d",&a)) .
Not using setprecision(9) when required.
Using the local variable of the same name when global variable was required to be used.
and many more.... :(
"While copy pasting query and update function calls of segment trees, forgetting to change arguments"
Not just it sometimes my update function calls the query function. And forgetting that +1 for right child B'(.
Write segment tree on half-open interval, and you will never ever forget about +1
It's not happened in codeforces' contest, but my silliest mistake is forgot to print newline character after the output (like what you did on your code!) (/.) I'm so sad...
I have done couple of those recently. They might not be the silliest but they have made me crazy. I am really diffident about myself now. And feeling disappointed a lot. :(
1) During round 291 div2, it took some time for me to be able to log into CF. When I finally logged in, I thought, "why not solve the problem C firstly and get more points?" So I opened problem C, coded it and submitted but failed in pretest. Then I realized that I understood the problem totally wrong. Then I went to problem A and B. Due to the failure in problem C, I got disheartened and it took some time and some submissions for me to solve A and B. After that I came back to problem C and coded it in a new approach. This time it passed pretests.
But interestingly, most of the people failed to solve problem C (At most 180 solved it as far as I remember). My solution failed also. It got MLE at test #18. Many people faced the same verdict (or TLE) due to the pattern of the problem. So finally I realized that it was so silly of me to try to solve problem C first which was probably harder than problem D. -_-
2) During the last round (292div2), I took a lot of time to solve problem C. You can check my submission. I used prime factorization and factorial concepts, and also did counting of prime factors. Finally I ended up with such huge code that took me upto 1 hour to solve the problem. I was so unhappy about that.
When I went to see others' solutions, I felt so ashamed of myself. I got amazed to see those simple-small solutions of problem C. I was truly so much ashamed. I wished I could bang my head on the wall and break it. -____-
These are the recent two unexpected scenarios that I had to face. But I have faced a lot more. CF is giving me hard time. Pretty hard time. I wish I could be a candidate master and go up to some level so that I can regain confidence and courage. Due to the worst contests, I cannot even feel normal. It is bad, really bad. :(
421B - Start Up, 6440978
I needed a set of symmetrical letters. And I've included letters AHIMNOPTUVWXY :D
I've recently written
if (a[i]>=0&&i<n)
instead ofif (i<n&&a[i]>=0)
forgot to set precision and ended up getting a wrong answer, after the contest just added setprecision and Ta-Dah Accepted.
I didn`t code anything wrong.
It was like 15 seconds left.
I uploaded the wrong file.
Segment tree. Size of subtree in a char. (RE6 instead of OK)
"Why the fuck pgcd(8,9) returns 8???"
-Wunused should help here
I keep a N defined to 10^5+e for declaring arrays but N was supposed to be 10^6 + e, I recieved hell lot of RE and I had to ask someone else to debug that code, I was ashamed of myself!
1: When i joined codeforces contest first time, i didn't know submitting a solution again skips old solution, so after passing pretests with correct solution, i made one more submission just to decrease execution time & memory resulting in loss of 50 points. :)
2: declared a counter of type char instead of int ,resulted in passing of pretests and failing of system test. :)
use "%d", instead of "%I64d" for read/write long long.
I subtracted 1 in a for loop from v.size(). Guess what happened when the input vector empty?
It became the maximum value of
size_t
sincesize_t
is unsigned. I was trapped by this once too.So, I think we should compile our code with
-Wall
. Then we can receive a warning of comparison between signed and unsigned integer expressions.(int)v.size()
My fault was about limits too. After the contest i went to bathroom and come back. Added 2 '0' character to code then it was AC.
instead of:
It passed pretests and failed systests
Wow. I guess that was pretty hard to find.
Wrote alphabet 'l' instead of digit '1' in one of the loops and 'l' was a variable...
I forgot to change magnitude of gen-test from 10^1 to 10^5, and then I mis-hacked two times trying to call TLE http://codeforces.net/contest/490/hacks/126123/test
Why the HELL no value equals 2?
9897544
24*1=1 is clearly the most stupid bug I have ever met :(
And some other silly bugs:
char n
instead ofint n
My code to find set in Disjoint-Set:
And many other bugs that I can't tell all of them.
In a bulgarian competition awhile ago, the input consisted of n, followed be two arrays of numbers. My input was:
While it should've been:
Of course, the problem had no feedback and the sample test case was somethint like:
I made a test generator with a slow solution, but my generator was producing the input in the wrong way too. Got 10 instead of 100 points for the problem.
The most common mistake for my case is that I use integer instead of long long or unsigned long long.
I forgot to add memset in a solution that contained test cases and debugged it for hours and finally had to ask it here on the blog !!!
I was about to become red, but failed systests.
I used somthing like this:
Got RE on systests. Adding the line (or using simple array)
got accepted.
In one of the question of heap, we were supposed to check whether a number is a power of two or not. Our team wasted around 30 minutes in
which were the last 30 minutes of ACM-ICPC Regionals :P and as soon as the contest got over, we figured out that the condition must be
if( (i&(i-1)) == 0)
X-(Can you explain what is the difference ? I don't get it.
==
has higher precedence than&
, so the expressioni & (i - 1) == 0
is evaluated asi & ((i - 1) == 0)
. See this.After looking an Editorial which metioned using long long and map,since pascal(the programming language I have used) doesn't have map,I tried to solve this problem using binary search instead of map.Generally I succeeded,but I didn't use long long(or int64 in pascal).. Sorry for the bad English:D
I've made many stupid mistakes over the years. Like taking int where long long is needed, not initializing or clearing containers like vectors, arrays, map etc. But the one I remember now is forgetting to comment out a output line used for debugging. It was hiding inside a condition and no testcase was using that condition, Alas!
But I learned a great thing after that. You can use "cerr" for debugging purpose. I think, every mistake is a step towards learning something new and interesting.
Once I noticed my code was wrong on n=1 and was printing 100 instead of 0.
So I added a line like this: if(n==1) print 100;
I assumed, that 1 is a prime number
I once commented out all my debugging outputs but forgot about the loops causing my solution to build a sparse table 10^10 times.
my silliest mistake was In Problem When I Read Problem As We Need To Check Equal Consecutive Elements and Make Operations on Them...While Problem Was To Check Equal Elements (Maybe not Consecutive) and Make on Them Operations
Was solving an almost-tree problem.
Wrote a lot of comments in the code, including a comment about running Floyd-Warshall. Finished the code. WA every time. An hour of debugging. No results.
Then I realized that I didn't actually write Floyd-Warshall, I just wrote the comment. Genius.
It may be
scanf("%d" , x).
And
printf("%d\n",&ans);
I think you are a tourist's fan
The first time I watched this video I didn't see "It's a joke" '-'
I saw it long time ago but at that time I thought with myself how all this advices are not useful XD
write a condition for n=1 separately because lots of hacks were there and I was happy that now I will get a chance to hack. if(n==1) cout<<"0\n"; After that I locked my submission then my solution got hacked because at n==1 we have to print 1. -_-
I considered 'y' as a consonant.
if (STR[i] == 0) { // do something }
Where STR is string.(you can understand what's wrong).
It's my mistake in problem E. (E is something that you want to solve in running contest.)
Feel bad.
I didn't read all the problems.
On the previous div3 i used binary search in C problem but i forgot to sort the vector so i had been searching for mistake for 30 minutes, but i solved it, though.
In a past contest long ago, my program computed the answer correctly but I output wrong variable. It passed the pretest but failed on system test, I only realized my mistake after the contest.
Today's Div3 declare size of array 1e5 instead 2e5
I've done this more than once:
Once I was implementing LCA function which needs matrix par[v][log v] for storing every 2i th ancestor of each vertex from 1 to v.
I declared my parent's matrix as
int par[maxv][maxlog]
, while using it likepar[log][vertex]
.The silly mistake took me about 5 hours before getting detected!
i modded the answer by 1e9+7 when there was no needed to print the answer modulo 1e9+7
Participating in it?
Instead of printing NO I printed N0.
Writing
const int mod = 10^9 + 7;
as module for hashes on ACM quarterfinal. Half an hour of debugging then, cause i was not even looking on part of the code where i needed hashes (just like my teammates), i believed it to be correct.I used
lower_bound(s.begin(),s.end(),x)
instead ofs.lower_bound(x)
, where s is a set. Didn't know the former is O(n).Once I wanted to check if a variable is 1, and by default I wrote an if statement like
if(x != 0)
but that x could be 2, 3 and so on.. Lost AC because of that
On Edu round #47, something like this:
int a[n];
and later ...
if(ai > n) break; else //do sth with a[ai]
">" is not ">=" ... I noticed the mistake right away but the penalty was 10 minutes.
One year ago on all-russian school students olympiad I had struct block. Something like that:
struct block { int len, number, ...; };
And I have std::set with compare block1.len < block2.len. So, set delete all blocks with the same length.
The most interesting that it solved first subgroup, so it was hard for me to find mistake(
One of my friends once accidentally wrote
int t = scanf("%d", &t);
I did it in today's contest in this problem.
The sad part is that I could not find this bug for one hour and contest ended and i couldnot submit d.
Wrote a & b instead of a % b... took me 2 hours to find the bug (by then contest ended).
Using ! instead of ~.
In a fenwick tree question I declared the array size by 1 less than required which got my solution to fail in system testing.
In a recent div 2 started a loop from 1 instead of 0 ... Got 4 wa.. only to realise this just seconds after contest ended :(
I missed Gold in EJOI 2019 because I forgot to
#define endl '\n'
, still regret itЯ оставил код который я не мог не как написать и пошёл гулять прихожу я смотою над самой глупой ошибкой я написал deb вместо def (для тех у кого python) :) :D ;)
It's russian meme if u dont know :)
ll s1,s2;
cin>>s1>>s1;
totally went from some random string error to AC after contest.
Thinking that the first submitted solution might fail system tests so submitting the 2nd solution when the contest is about to end and converting +70 to -20. And then seeing my first solution passing all test cases.
When trying to find the union of ranges, I'm supposed to first sort the ranges. I may sort them based on the left value or I may sort them based on the right value.
Guess what I wrote instead...
(This is before I learned that I don't need to make a custom comparison function to sort pairs)
One state of my DP function could hold values from 0-3. So I declared DP table as DP[..][..][3].
In my second last contest i was accessing n — 1 th index of n — 1 sized vector. This mistake ruined the contest for me.
Once when I make a segment tree
and once I use modulo where as the answer fit long long type
In Segment Trees:
In the Singapore NOI this year, one of the problems involved making a segment tree on the difference array $$$D$$$ of another array $$$A$$$.
When the size of array $$$A$$$ is 1, the difference array $$$D$$$ is of size 0.. which means the segment tree would infinitely recurse because segment size is 1 (the base case) would never be fulfilled for any node in the tree...
I spent almost 2 hours trying to debug this, failed to debug it for the entire time, and ended up one rank away from the gold medal...
Used python
I have got Segmentation Fault a few times (mostly in dp problems) because I forgot to change it's maximum size.
Recently, forgot to remove unneeded stuffs in the code that reduce the run time. It is already sorted but I sort it again to make sure but slow down the program significantly
Oh my stupid make me lose 1 point to be an Expert haha ;-;
Mistyped an 'j' as an 'i' and spent the next hour debugging my code but was only able to find my mistake after contest ended because those two characters look awfully simmiliar
90621775 90617305
This was from a while ago but I'm still kinda mad about it.
:(
in today's contest(29/12/2020), instead of using goto to input the next testcase, I mistakenly used return 0, realized it 10 second before the contest was going to end, still couldn't fix it in time, code was AC afterwards.
Yeah, I found this blog just to vent >_<
Write functions instead.
misspelling "impossible" as "impossibe" and spending almost an hour debugging
Cue every single time I failed system tests due to int overflow...
yep that's part of my template now :/
In Codeforces global round 11, I mentally solved B,D,E (In fact they are the same as the editorial solutions) but was able to implement none of them because on B I have an error with flags that I couldn't debug, and I just somehow couldn't implement D or E in 90 minutes...
I also have a lot of overflow and typoes. For me, most of the times implementing is much harder than solving.
Getting the input in the wrong format and debugging my code for hours :)
Wrong format in output twice: AGC051B Same problem
Printing 1000 gives this
It was in a rated contest. I misread the problem and therefore added an unneeded edge case. I forgot to print a new line in the edge case, which caused by program to WA. I didn't realize the mistake in-contest but had I removed the edge-case code or printed a new line, I would have ACed. Furthermore, as my luck had it, this problem was rated 1500, and my rating at the time was 1300 (I would've had a huge rating boost had I gotten it right).
Instead of 1LL<<k , I used 1<<k and kept getting wa, after the contest just changing that gave ac :(
Binary searched over the range (1, i — 1) instead of (1, i) ._.
used >0 instead of >=0 got WA 2 times then realised this mistake but by this time the game was over.
Summary: -Wall saves your life
In one of the recent contest i was quite sure about my idea but it was giving wrong answer, After an hour i figured out that i have not put the break condition in one the loop, later it give Ac after putting it.
I few months back, i wrote
if(f&1&&k==5)
instead ofif((f&1)&&(k==5))
.Not reading the constraints.
eating 2 shawarmas before the contest
Some mistakes made by me:
1.redefine the variable (It happened many times to me before.)
For example, I wrote code such that:
2.define a function such that
int Min(int n,int m)
but n and m can be 64-bit signed integers3.use
define
incorrectly such thatdefine min(a,b) ((a)<(b)?(a):(b))
If
a
is a function, it will call the function twice.If
a
is a recursion function, it will call the function $$$2^k$$$ times. ($$$k$$$ is the number of plies)4.modulo $$$P$$$ anywhere except when printing the answer:
5.forget that some functions with return values like
size()
are unsigned:If
v
is empty, thenv.size()=0
so thatv.size()-1=18446744073709551615
.( so please write
int(v.size())
instead ofv.size()
)6.use
break
somewhere that should becontinue
:7.forget to clear the array when there are two or more test cases
( so please clear it in time and double samples to test your program )
8.clear the array in time but get TLE
For example, you are given $$$n$$$ integers in the range $$$[0,10^6]$$$ and asked if $$$x$$$ appears for some integers $$$x$$$. There are $$$10^4$$$ test cases and it is guaranteed that $$$\sum n$$$ doesn't exceed $$$10^6$$$.
It is obvious that we need a bool array
vis
to record whether one integer appears. But if you clear the whole array every time, you will get TLE because it is too slow. We should also record the positions we visit so that we can just restore these elements. In fact, in this example, we don't need to record it because we can easily know the elements we visit (which are just we are given).So I resumed doing CP 3 months after getting placed and made the silliest error. Thankfully it did not happen in a contest :)
Are you trying to binary search, but only doing
++l;
and--r;
, thus turning the $$$\log n$$$ factor into $$$n$$$?forgot to put = , in if(x>=y)
and just after finishing contest i recognized this . . . it was to late :(
joining the contest
wasted 3 hours rethinking the algo where we actually forgot to use long long, realised minutes after the contest ends. we should've known better =(
Where s is a set.
I thought it was O(log n), but according to the C++ Standard, it is O(n).
set::lower_bound takes advantage of knowing it's applying this operation on a set and it's properties. Ensuring logN time.
While std::lower_bound only promises logN time if the iterators are random. Set iterator is a not a random one ( as far as I know, I don't mainly use C++), so that explains the time.
Thanks, I didn't know that :)
Once I forgot to take input LoL
My friend took TLE in a problem because in binary search he put
Instead of:
Today was awful for me. I decided not to join today's round but I wondered about problems. So I opened problem D and started reading. When I am thinking about the problem, I forgot it is an ongoing contest. I found a solution and code it. To check it against test cases, I submitted it. When I have realized it is an ongoing contest, it was too late. I couldn't do anything because it was in the last minutes of the contest. I will get -190 delta :(
Had to check if (x%2==1) and didnt realize that since x can less than zero had to write ((x%2+2)%2) took me an hour during the contest to find it :( . Was pretty easy problem. Another one was an input where I placed n=number of rows and len = length of string but because i had the habit of using n for string length instead of 'len' was using 'n' everywhere and was not able to detect the mistake.
For powers of two, you can do
(x&(n-1))
instead ofx%n
where $$$n=2^k$$$ ($$$n=2$$$ in your case, so it'd be(x&1)
). Note that you need to use parentheses, because==
is evaluated before&
.Hello, fellow necroposters! Not sure if it is considered silly, but once I wrote
if (sums[left >= time])
instead of
if (sums[left] >= time)
And it even passed pretests...
Submitted a solution of a problem to some different problem in live contest.
Although it seems silly, but for several times, I forgot to build the tree while using segment tree to solve problems :(
for(int i=0;i<n;i++) {
for(int j=0;j<n;i++)
}
and i keep forgetting that i did i++ instead of j++ :(
I often put the size of my segment tree as n instead of 4*n.
Submitted a program with some assert() and got pretests passed.
After system test, I got RE because my assert() failed. However, the program itself could pass system test! It's just my assert() that was wrong.
During one icpc regional there was a problem where you have to output numbers as 1st, 2nd, 3rd, etc. [https://ecna20.kattis.com/problems/allinthefamily]
I thought of the following code:
It wasn't until I generated a massive test case that I saw my problem:
A and B are 11st cousins
During the contest CodeCraft-21 and Codeforces Round 711 (Div. 2) I got WA because of the extra whitespace in the printout, 111401720.
cout << "! 0 0 " << endl;
After the contest I removed the whitespace and got AC, 111405866.
cout << "! 0 0" << endl;
Named an array "read" in a recent Div 2. Got runtime error in test 1. My compiler was showing no errors. Then few days later a blog comes up here showing we can't name a variable "read" in CF. Lol. https://codeforces.net/contest/1573/submission/129233057
[Deleted]
Data type overflow...
include <bits/stdc++h>
I forgot the '.' .
That's you bro. xD.
There was once a very easy A problem which needed a frequency array. The loop I used to loop over it had to be <=100. I forgot the = sign and failed the system testing. :(
hashing, unsigned long long, with base=(1ull<<32).
One of my friends told me this and I couldn't help laughing out loudly:(
Handled the edge case for a div3 B (round 787) wrongly. https://codeforces.net/problemset/problem/1675/B
If the last element is 0 you cannot divide at all, should return -1 since it’s impossible. But I returned 0 and didn’t notice it for over 30 minutes until the contest ended. I tried to modify many different parts thinking my logic is wrong not the edge case itself.
I even tried the test case [0,0] while debugging and I didn’t think my output of 0 for that test case is wrong. So dumb lmao
int p,q; cin>>q>>q;
Used i for indexing instead of j inside nested loop and somehow it passed pretest 1 Lmfao i was so pissed after noticing it while debugging
I used
in a
sort
as a comparing function in the problem D in Round #792.It passed the pretest but got RE on the system test.
It was the next morning when I found it FSTed, then I changed it to
Accepted.
In a contest, in a graph problem I took global arrays for adjency list and forgot to clear the array after using it. It took me around 30-40mins to debugging it :(
Binary searched from 1 instead of 0 so instead of having 2300 performance I FST to 1850
Unfortunately, in the last contest, this:
was the only thing that separated me from AC on problem D :(
So because of this, after gaining my first 1700+ rating, I lost 94 rating in next contest