2

What is the silliest mistake you have done in a contest ?

 2 years ago
source link: http://codeforces.com/blog/entry/16474
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
By Fear_Is_An_Illusion, 7 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.

7 years ago, # |

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.

  • 7 years ago, # ^ |

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

  • 3 years ago, # ^ |

    Three years down the lane, still relevant!

    • 14 months ago, # ^ |

      6 years down the lane still revelent

      • 14 months ago, # ^ |

        this except with the Zashikhin prime

      • 119 minutes ago, # ^ |

        7 years down the lane still revelent

7 years ago, # |

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

7 years ago, # |

Forget to print the answer modulo some number :D

7 years ago, # |

Rev. 2  

+37

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

7 years ago, # |

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

7 years ago, # |

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

  • 7 years ago, # ^ |

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

7 years ago, # |

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

  • 10 months ago, # ^ |

    Rev. 2  

    +67

    • 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 months ago, # ^ |

      You can hack yourself in this case

7 years ago, # |

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

string s;
...
{
    string s;
    ...
    // using s as first s;
}
  • 7 years ago, # ^ |

    -Wshadow is your friend

  • 7 years ago, # ^ |

    Rev. 2  

    0

    Same as you. It took about three hours to debug :|

7 years ago, # |

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

7 years ago, # |

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.

7 years ago, # |

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

7 years ago, # |

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

7 years ago, # |

Rev. 2  

0

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)

7 years ago, # |

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

7 years ago, # |

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

  • 7 years ago, # ^ |

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

    • 10 months ago, # ^ |

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

7 years ago, # |

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

7 years ago, # |

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

7 years ago, # |

421B - Start Up, 6440978

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

7 years ago, # |

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

  • 15 months ago, # ^ |

    The comment is hidden because of too negative feedback, click here to view it

7 years ago, # |

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

7 years ago, # |

I didn`t code anything wrong.

It was like 15 seconds left.

I uploaded the wrong file.

7 years ago, # |

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

7 years ago, # |

int pgcd(int a,int b)
{
    return b==0?a:(b%a,a);
}

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

  • 7 years ago, # ^ |

    -Wunused should help here

7 years ago, # |

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!

7 years ago, # |

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

7 years ago, # |

Rev. 2  

0

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

7 years ago, # |

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

  • 7 years ago, # ^ |

    Rev. 2  

    +3

    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.

    • 7 years ago, # ^ |

      (int)v.size()

7 years ago, # |

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.

7 years ago, # |

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

instead of:

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

It passed pretests and failed systests

  • 7 years ago, # ^ |

    Wow. I guess that was pretty hard to find.

7 years ago, # |

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

7 years ago, # |

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

7 years ago, # |

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?

7 years ago, # |

if (xx >= n || xx < 0 || yy < 0 || xx >= m)
	continue;
9897544

7 years ago, # |

using OR logic instead AND

7 years ago, # |

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

7 years ago, # |

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.

7 years ago, # |

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.

7 years ago, # |

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

7 years ago, # |

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

7 years ago, # |

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.

7 years ago, # |

vector<double> values;
...
double sum = accumulate(values.begin(), values.end(), 0);

7 years ago, # |

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

  • 14 months ago, # ^ |

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

    • 14 months ago, # ^ |

      Rev. 2  

      0

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

7 years ago, # |

Rev. 4  

0

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

7 years ago, # |

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

3 years ago, # |

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.

3 years ago, # |

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;

3 years ago, # |

I assumed, that 1 is a prime number

3 years ago, # |

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

3 years ago, # |

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

3 years ago, # |

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.

3 years ago, # |

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

  • 3 years ago, # ^ |

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

    • 24 hours ago, # ^ |

      Rev. 2  

      +6

      I think you are a tourist's fan

3 years ago, # |

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

3 years ago, # |

I considered 'y' as a consonant.

3 years ago, # |

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.

3 years ago, # |

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.

3 years ago, # |

I didn't read all the problems.

3 years ago, # |

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.

3 years ago, # |

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.

3 years ago, # |

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

3 years ago, # |

Rev. 2  

+3

I've done this more than once:

while (!q.isEmpty()) {
    int cur = in.nextInt(); // instead of q.poll() =(
}

3 years ago, # |

Rev. 2  

0

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!

3 years ago, # |

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

3 years ago, # |

Participating in it?

3 years ago, # |

Instead of printing NO I printed N0.

3 years ago, # |

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.

3 years ago, # |

Rev. 3  

+3

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

3 years ago, # |

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

3 years ago, # |

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.

3 years ago, # |

Rev. 2  

+8

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(

3 years ago, # |

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

3 years ago, # |

Rev. 3  

0

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.

3 years ago, # |

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

15 months ago, # |

Using ! instead of ~.

14 months ago, # |

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

14 months ago, # |

Rev. 2  

0

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

14 months ago, # |

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

14 months ago, # |

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

  • 14 months ago, # ^ |

    It's russian meme if u dont know :)

14 months ago, # |

ll s1,s2;

cin>>s1>>s1;

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

14 months ago, # |

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.

14 months ago, # |

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)

14 months ago, # |

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

14 months ago, # |

1.had to traverse from a-z....i used ""for(i=0;i<25;i++){ll ss=i-'a';........}""....even in contest time i couldnot figure out the problem....i find it after contest.......

2.infinity=1e12...(where some results was bigger than that)

3.not calling seive function....(still pretests was passed) and then wrong answer on test case 2

etc.......

14 months ago, # |

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

14 months ago, # |

Rev. 4  

+10

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

14 months ago, # |

In Segment Trees:

if (r < lc[p] || lc[p] > r) return;
// should be
if (r < lc[p] || l > rc[p]) return;

14 months ago, # |

Rev. 2  

+25

In the Singapore NOI this year, one of the problems involved making a segment tree on the difference array DD of another array AA.

When the size of array AA is 1, the difference array DD 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...

14 months ago, # |

Used python

13 months ago, # |

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

13 months ago, # |

When I was writing the code, I missed one header file, which cost me a full 400 points.

11 months ago, # |

Rev. 2  

0

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

11 months ago, # |

while (some condition);

11 months ago, # |

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

11 months ago, # |

90621775 90617305

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

11 months ago, # |

froepen("call.in", "r", stdin);

10 months ago, # |

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

  • 10 months ago, # ^ |

    Write functions instead.

  • 10 months ago, # ^ |

    So now you understand why most of the people use a 'solve()' function and call it for each test case from main()

10 months ago, # |

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

10 months ago, # |

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

  • 10 months ago, # ^ |

    Rev. 3  

    -26

    The comment is hidden because of too negative feedback, click here to view it
    • 10 months ago, # ^ |

      yep that's part of my template now :/

10 months ago, # |

Rev. 2  

-7

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.

10 months ago, # |

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

10 months ago, # |

I was gonna write s.substr(0,4) but instead wrote s.substr(0.4). And it got compiled successfully (welcome to C++). I didn't notice what was wrong until the next day.

10 months ago, # |

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

10 months ago, # |

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

10 months ago, # |

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

10 months ago, # |

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

10 months ago, # |

Summary: -Wall saves your life

10 months ago, # |

1.not changing line. 2.i didn't knew that input with spaces can be accepted using cin>>a>>b. These are some of silliest mistakes i had done.

10 months ago, # |

i wrote if(s[i]==0) instead of if(s[i]=='0')

realizing this after 1hr

10 months ago, # |

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.

10 months ago, # |

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

10 months ago, # |

Not reading the constraints.

10 months ago, # |

forgot to register

10 months ago, # |

eating 2 shawarmas before the contest

10 months ago, # |

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 2k2k times. (kk is the number of plies)

4.modulo PP 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 nn integers in the range [0,106][0,106] and asked if xx appears for some integers xx. There are 104104 test cases and it is guaranteed that ∑n∑n doesn't exceed 106106.

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

10 months ago, # |

I lost a lot of time just because of this __gcd(0,0) :V

29 hours ago, # |

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 hours ago, # ^ |

    Are you trying to binary search, but only doing ++l; and --r;, thus turning the lognlog⁡n factor into nn?

    • 3 hours ago, # ^ |

      Precisely :)

28 hours ago, # |

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

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

27 hours ago, # |

joining the contest

25 hours ago, # |

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

21 hour(s) ago, # |

1.Used inbuilt pow() function, Realized mistake after contest.
2.Later used, 1<<n but forgot to use 1LL<<n

21 hour(s) ago, # |

Rev. 3  

-11

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

19 hours ago, # |

Once I forgot to take input LoL

16 hours ago, # |

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

int mid = (l + r);

Instead of:

int mid = (l + r) / 2;

15 hours ago, # |

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

15 hours ago, # |

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 hours ago, # ^ |

    For powers of two, you can do (x&(n-1)) instead of x%n where n=2kn=2k (n=2n=2 in your case, so it'd be (x&1)). Note that you need to use parentheses, because == is evaluated before &.

    • 3 hours ago, # ^ |

      Ah yes!! Funny I know this fact but during contests I always forget. Thanks!!

12 hours ago, # |

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

2 hours ago, # |

for (int i = n; i >= 1; i++) {
    /// ...
}

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK