Fear_Is_An_Illusion's blog

By Fear_Is_An_Illusion, 3 years ago, In English,

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.

 
 
 
 
  • Vote: I like it  
  • +30
  • Vote: I do not like it  

»
3 years ago, # |
  Vote: I like it +31 Vote: I do not like it

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 of 1e9 + 7. Whoops.

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +2 Vote: I do not like it

    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?)

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it -23 Vote: I do not like it

    Three years down the lane, still relevant!

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

In a CF round I got RE because I must change 100 to 500! I don't want to think about that :(

»
3 years ago, # |
  Vote: I like it -8 Vote: I do not like it

Forget to print the answer modulo some number :D

»
3 years ago, # |
Rev. 2   Vote: I like it +37 Vote: I do not like it

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 :(

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I used maxn = 501 instead of maxn = 5010 in COCI contest and got 42 points instead of 140.

»
3 years ago, # |
  Vote: I like it +36 Vote: I do not like it

Factorizing 9: I wrote 9 = 3*3*3
:/

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    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 :(

»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it

I locked my problem without checking it properly, and hello div.2

»
3 years ago, # |
  Vote: I like it +23 Vote: I do not like it

NEERC ACM quarterfinal. There was two variables with the same name:

string s;
...
{
    string s;
    ...
    // using s as first s;
}
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 :/

»
3 years ago, # |
  Vote: I like it +21 Vote: I do not like it

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.

»
3 years ago, # |
  Vote: I like it -8 Vote: I do not like it

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

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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...

»
3 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Using 2000 as INF to initialize variable that contains smallest number when the range of answer was 1 — 10^6. (the small input range of answer was 1 — 10^2)

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it
  1. Using int when long long was required.

  2. 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.

  3. Using wrong initial values for max(0 when maximum element could be negative) or min variables(INT_MAX instead of 1e18).

  4. While copy pasting query and update function calls of segment trees, forgetting to change arguments.

  5. Wrongly inserting intial elements in a vector. push_back(some value) twice instead of just once.

  6. while(scanf("%d",&a)!=EOF) instead of while(scanf("%d",&a)) .

  7. Not using setprecision(9) when required.

  8. Using the local variable of the same name when global variable was required to be used.

and many more.... :(

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    "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'(.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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...

»
3 years ago, # |
  Vote: I like it +2 Vote: I do not like it

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. :(

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

421B - Start Up, 6440978

I needed a set of symmetrical letters. And I've included letters AHIMNOPTUVWXY :D

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I've recently written if (a[i]>=0&&i<n) instead of if (i<n&&a[i]>=0)

»
3 years ago, # |
  Vote: I like it +1 Vote: I do not like it

forgot to set precision and ended up getting a wrong answer, after the contest just added setprecision and Ta-Dah Accepted.

»
3 years ago, # |
  Vote: I like it +52 Vote: I do not like it

I didn`t code anything wrong.

It was like 15 seconds left.

I uploaded the wrong file.

»
3 years ago, # |
  Vote: I like it +16 Vote: I do not like it

Segment tree. Size of subtree in a char. (RE6 instead of OK)

»
3 years ago, # |
  Vote: I like it +44 Vote: I do not like it
int pgcd(int a,int b)
{
    return b==0?a:(b%a,a);
}

"Why the fuck pgcd(8,9) returns 8???"

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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!

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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. :)

»
3 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

use "%d", instead of "%I64d" for read/write long long.

»
3 years ago, # |
  Vote: I like it +6 Vote: I do not like it

I subtracted 1 in a for loop from v.size(). Guess what happened when the input vector empty?

  • »
    »
    3 years ago, # ^ |
    Rev. 2   Vote: I like it +3 Vote: I do not like it

    It became the maximum value of size_t since size_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.

»
3 years ago, # |
  Vote: I like it -8 Vote: I do not like it

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.

»
3 years ago, # |
  Vote: I like it +31 Vote: I do not like it
for (int i = n - 1; i--; i >= 0)

instead of:

for (int i = n - 1; i >= 0; i--)

It passed pretests and failed systests

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Wow. I guess that was pretty hard to find.

»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Wrote alphabet 'l' instead of digit '1' in one of the loops and 'l' was a variable...

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.ru/contest/490/hacks/126123/test

»
3 years ago, # |
  Vote: I like it +3 Vote: I do not like it
bool vis[MAXN];
bool dfs(int cur) {
    vis[cur] = 1;
    // some code to detect a cycle in a graph
    vis[cur] = 2;
    return 0;
}

Why the HELL no value equals 2?

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it
if (xx >= n || xx < 0 || yy < 0 || xx >= m)
	continue;

9897544

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

using OR logic instead AND

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

used a float instead of double, got over flow after system test.

»
3 years ago, # |
  Vote: I like it +11 Vote: I do not like it

24*1=1 is clearly the most stupid bug I have ever met :(

And some other silly bugs:

  • char n instead of int n

  • My code to find set in Disjoint-Set:

int find(int x) {
    if (lab[x]<0) return (x);
    return (lab[x]);
    lab[x]=find(lab[x]);
}
  • Using c++ std::set (this may cause unexpected behavior):
set<int> s;
for (set<int>::iterator it=s.begin();it!=s.end();it++) {
    if (blablabla) s.erase(*it);
}
  • Comparing bignum from last digit to first digit instead of first digit to last digit.
  • Getting long long overflow (unsigned long long is ok) in 458B - Distributed Join, this made me lose a T-shirt :(
  • Wrong time-complexity calculation: In 391C3 - The Tournament, I thought my algorithm was O(N^2logN), when it was only O(NlogN). I couldn't solve this problem during the contest and also lost a T-shirt :(
  • Forget about multiple data sets in one input file.

And many other bugs that I can't tell all of them.

»
3 years ago, # |
  Vote: I like it +5 Vote: I do not like it

In a bulgarian competition awhile ago, the input consisted of n, followed be two arrays of numbers. My input was:

n
a1 b1
a2 b2
.
.

While it should've been:

n
a1 a2 a3...
b1 b2 b3...

Of course, the problem had no feedback and the sample test case was somethint like:

2
1 0
0 1

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.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

The most common mistake for my case is that I use integer instead of long long or unsigned long long.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 !!!

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I was about to become red, but failed systests.

I used somthing like this:

vector<int> v;
...
for (int i = v[0]; i <= n; i++) {
}

Got RE on systests. Adding the line (or using simple array)

if (!v.empty()) {
  ...
}

got accepted.

»
3 years ago, # |
  Vote: I like it +8 Vote: I do not like it
vector<double> values;
...
double sum = accumulate(values.begin(), values.end(), 0);
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

if(i&(i-1) == 0) {
    cout<<"Power of two";
} else {
    cout<<"Not a power of two";
}

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-(

»
3 years ago, # |
Rev. 4   Vote: I like it 0 Vote: I do not like it

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

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

In GCJ 2014 I lost a T-Shirt due to the following stupid mistake. ^^

java Program -Xss8M

Verdict: StackOverflow

Instead of: java -Xss8M Program

Verdict: Accepted

»
5 weeks ago, # |
  Vote: I like it +4 Vote: I do not like it

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.

»
5 weeks ago, # |
  Vote: I like it +75 Vote: I do not like it

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;

»
5 weeks ago, # |
  Vote: I like it +7 Vote: I do not like it

I assumed, that 1 is a prime number

»
5 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

I once commented out all my debugging outputs but forgot about the loops causing my solution to build a sparse table 10^10 times.

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
4 weeks ago, # |
  Vote: I like it +86 Vote: I do not like it

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.

»
4 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

It may be scanf("%d" , x).

»
4 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

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. -_-

»
4 weeks ago, # |
  Vote: I like it +12 Vote: I do not like it

I considered 'y' as a consonant.

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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.

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Sometimes, we've to print something and get to return out of main.

So, I generally use

return cout<<"YES",0;

But in haste, I forgot to use the keyword return, and got -50 to correct it.

»
4 weeks ago, # |
  Vote: I like it +43 Vote: I do not like it

I didn't read all the problems.

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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.

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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.

»
4 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

Today's Div3 declare size of array 1e5 instead 2e5

»
4 weeks ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

I've done this more than once:

while (!q.isEmpty()) {
    int cur = in.nextInt(); // instead of q.poll() =(
}
»
4 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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 like par[log][vertex] .

The silly mistake took me about 5 hours before getting detected!

»
4 weeks ago, # |
  Vote: I like it +10 Vote: I do not like it

i modded the answer by 1e9+7 when there was no needed to print the answer modulo 1e9+7

»
4 weeks ago, # |
  Vote: I like it +14 Vote: I do not like it

Participating in it?

»
4 weeks ago, # |
  Vote: I like it +5 Vote: I do not like it

Instead of printing NO I printed N0.

»
4 weeks ago, # |
  Vote: I like it +11 Vote: I do not like it

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.

»
4 weeks ago, # |
Rev. 3   Vote: I like it +3 Vote: I do not like it

I used lower_bound(s.begin(),s.end(),x) instead of s.lower_bound(x), where s is a set. Didn't know the former is O(n).

»
4 weeks ago, # |
  Vote: I like it +3 Vote: I do not like it

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

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

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.

»
4 weeks ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

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(