Fear_Is_An_Illusion's blog

By Fear_Is_An_Illusion, 10 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.

| Write comment?
»
10 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.

  • »
    »
    10 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?)

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

    Three years down the lane, still relevant!

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

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

Forget to print the answer modulo some number :D

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

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

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

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

  • »
    »
    10 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 :(

»
10 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

  • »
    »
    4 years ago, # ^ |
    Rev. 2   Vote: I like it +67 Vote: I do not like it
    • lock problem
    • see other's code
    • find a test case that the outputs from two programs are different
    • "Wow!+100!"
    • unsuccessful hacking attempt
    • failed system test
»
10 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;
}
»
10 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 :/

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

»
10 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

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

»
10 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

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

  • »
    »
    10 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'(.

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

      Write segment tree on half-open interval, and you will never ever forget about +1

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

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

»
10 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

»
10 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)

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

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

»
10 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)

»
10 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???"

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

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

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

»
10 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?

  • »
    »
    10 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.

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

»
10 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

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

    Wow. I guess that was pretty hard to find.

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

»
10 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.net/contest/490/hacks/126123/test

»
10 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?

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

9897544

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

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

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

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

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

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

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

    Can you explain what is the difference ? I don't get it.

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

      == has higher precedence than &, so the expression i & (i - 1) == 0 is evaluated as i & ((i - 1) == 0). See this.

»
10 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

»
6 years 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.

»
6 years 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;

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

I assumed, that 1 is a prime number

»
6 years 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.

»
6 years 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

»
6 years 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.

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

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

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

    And printf("%d\n",&ans);

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

      I think you are a tourist's fan

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

        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

»
6 years 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. -_-

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

I considered 'y' as a consonant.

»
6 years 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.

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

I didn't read all the problems.

»
6 years 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.

»
6 years 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.

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

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

»
6 years 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() =(
}
»
6 years 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!

»
6 years 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

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

Participating in it?

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

Instead of printing NO I printed N0.

»
6 years 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.

»
6 years 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).

»
6 years 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

»
6 years 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.

»
6 years 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(

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

One of my friends once accidentally wrote int t = scanf("%d", &t);

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

I did it in today's contest in this problem.

//outside of bfs loop
   int x,y;
   cin>>x>>y;
   
   while(sz(pq)){
       //inside of bfs loop
       int x=cur_row;
       int y=cur_col;

       // then checking against these local variables thinking that I am checking against the 
       //variables i have declared outside of the loop;  
   }

The sad part is that I could not find this bug for one hour and contest ended and i couldnot submit d.

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

Wrote a & b instead of a % b... took me 2 hours to find the bug (by then contest ended).

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

Using ! instead of ~.

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

In a fenwick tree question I declared the array size by 1 less than required which got my solution to fail in system testing.

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

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

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

I missed Gold in EJOI 2019 because I forgot to #define endl '\n', still regret it

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

Я оставил код который я не мог не как написать и пошёл гулять прихожу я смотою над самой глупой ошибкой я написал deb вместо def (для тех у кого python) :) :D ;)

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

ll s1,s2;

cin>>s1>>s1;

totally went from some random string error to AC after contest.

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

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.

»
4 years ago, # |
  Vote: I like it -6 Vote: I do not like it

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.

//possibility 1
bool comp(pair <int, int> a, pair <int, int> b){
  return a.first<b.first;
}
//possibility 2
bool comp(pair <int, int> a, pair <int, int> b){
  return a.second<b.second;
}

Guess what I wrote instead...

bool comp(pair <int, int> a, pair <int, int> b){
  return a.first<b.second;
}

(This is before I learned that I don't need to make a custom comparison function to sort pairs)

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

One state of my DP function could hold values from 0-3. So I declared DP table as DP[..][..][3].

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

In my second last contest i was accessing n — 1 th index of n — 1 sized vector. This mistake ruined the contest for me.

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

Once when I make a segment tree

    ll query(int l, int r, int ct, int lt, int rt) {
        if (lt >= r || l >= rt) return 0;     /// Out-range
        if (lt >= l && r >= rt) return t[ct]; ///  In-range

        int mt = (lt + rt) >> 1; /// Midle
        return query(l, r, ct * 2 + 1, lt, mt); /// <----------------
             + query(l, r, ct * 2 + 2, mt, rt);
    }

and once I use modulo where as the answer fit long long type

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

In Segment Trees:

if (r < lc[p] || lc[p] > r) return;
// should be
if (r < lc[p] || l > rc[p]) return;
»
4 years ago, # |
Rev. 2   Vote: I like it +25 Vote: I do not like it

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

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

Used python

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

I have got Segmentation Fault a few times (mostly in dp problems) because I forgot to change it's maximum size.

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

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

»
4 years ago, # |
  Vote: I like it +2 Vote: I do not like it
while (some condition);
»
4 years ago, # |
  Vote: I like it +1 Vote: I do not like it

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

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

90621775 90617305

This was from a while ago but I'm still kinda mad about it.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it
froepen("call.in", "r", stdin);

:(

»
4 years ago, # |
  Vote: I like it +2 Vote: I do not like 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 >_<

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

misspelling "impossible" as "impossibe" and spending almost an hour debugging

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

Cue every single time I failed system tests due to int overflow...

»
4 years ago, # |
Rev. 2   Vote: I like it -7 Vote: I do not like it

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.

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

Getting the input in the wrong format and debugging my code for hours :)

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

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

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

Instead of 1LL<<k , I used 1<<k and kept getting wa, after the contest just changing that gave ac :(

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

Binary searched over the range (1, i — 1) instead of (1, i) ._.

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

used >0 instead of >=0 got WA 2 times then realised this mistake but by this time the game was over.

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

Summary: -Wall saves your life

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

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.

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

I few months back, i wrote if(f&1&&k==5) instead of if((f&1)&&(k==5)).

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

Not reading the constraints.

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

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

eating 2 shawarmas before the contest

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

Some mistakes made by me:

1.redefine the variable (It happened many times to me before.)

For example, I wrote code such that:

#include<bits/stdc++.h>
using namespace std;
int n,m;
void solve()
{
	//... 
	//something which uses n and m
}
int main()
{
	int n,m;
	cin>>n>>m;//which uses n and m defined in the main function  
	solve();
	return 0;
}

2.define a function such that int Min(int n,int m) but n and m can be 64-bit signed integers

3.use define incorrectly such that define 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:

//a=(...)%P;
//b=(...)%P;
printf("%d\n",a+b);

5.forget that some functions with return values like size() are unsigned:

for(int i=0;i<v.size()-1;++i)//v is a vector
{
	//...
}

If v is empty, then v.size()=0 so that v.size()-1=18446744073709551615.

( so please write int(v.size()) instead of v.size() )

6.use break somewhere that should be continue:

int T;
cin>>T;
while(T--)
{
	int n,m;
	cin>>n>>m;
	if(n<=2||m<=2)
	{
		puts("-1");
		break;//here should be "continue" 
	}
	//...
}

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

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

So I resumed doing CP 3 months after getting placed and made the silliest error. Thankfully it did not happen in a contest :)

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

    Are you trying to binary search, but only doing ++l; and --r;, thus turning the $$$\log n$$$ factor into $$$n$$$?

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

forgot to put = , in if(x>=y)

and just after finishing contest i recognized this . . . it was to late :(

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

joining the contest

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

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

»
3 years ago, # |
Rev. 3   Vote: I like it -11 Vote: I do not like it
auto it = lower_bound(s.begin(), s.end(), x);

Where s is a set.

I thought it was O(log n), but according to the C++ Standard, it is O(n).

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

    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.

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

Once I forgot to take input LoL

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

My friend took TLE in a problem because in binary search he put

int mid = (l + r);

Instead of:

int mid = (l + r) / 2;
»
3 years ago, # |
  Vote: I like it +17 Vote: I do not like it

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

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

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.

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

    For powers of two, you can do (x&(n-1)) instead of x%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 &.

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

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

»
3 years ago, # |
  Vote: I like it +17 Vote: I do not like it
for (int i = n; i >= 1; i++) {
    /// ...
}
»
3 years ago, # |
  Vote: I like it +14 Vote: I do not like it

Submitted a solution of a problem to some different problem in live contest.

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

Although it seems silly, but for several times, I forgot to build the tree while using segment tree to solve problems :(

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

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

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

I often put the size of my segment tree as n instead of 4*n.

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

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.

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

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:

if n % 10 == 1:
    return n + "st"
if n % 10 == 2:
    return n + "nd"
if n % 10 == 3:
    return n + "rd"
else:
    return n + "th"

It wasn't until I generated a massive test case that I saw my problem: A and B are 11st cousins

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

During the contest CodeCraft-21 and Codeforces Round 711 (Div. 2) I got WA because of the extra whitespace in the printout, 111401720.

WA

After the contest I removed the whitespace and got AC, 111405866.

AC
»
3 years ago, # |
  Vote: I like it +16 Vote: I do not like it
int mid = (l+r)>>2;
»
3 years ago, # |
  Vote: I like it +4 Vote: I do not like it

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

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

[Deleted]

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

Data type overflow...

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

include <bits/stdc++h>

I forgot the '.' .

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

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

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

hashing, unsigned long long, with base=(1ull<<32).

One of my friends told me this and I couldn't help laughing out loudly:(

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

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

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

int p,q; cin>>q>>q;

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

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

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

I used

bool cmp(const ll&A,const ll&B){return a[A]+A>=a[B]+B;}

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

bool cmp(const ll&A,const ll&B){return a[A]+A>a[B]+B;}

Accepted.

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

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

»
3 years ago, # |
Rev. 3   Vote: I like it +3 Vote: I do not like it
if(n==1){
   cout<<"0\n";
   return;
}
for(int i=0;i<n;i++){
   cin>>v[i];
}
// implementation
»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Binary searched from 1 instead of 0 so instead of having 2300 performance I FST to 1850

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

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