yelghareeb's blog

By yelghareeb, history, 7 years ago, In English

In problem 768E - Game of Stones, there are n piles, each with s stones (1 <= s <= 60). Players alternate moving as in the ordinary Nim with 1 restriction: no move can be made more than once on a pile (e.g. cannot remove 4 stones from pile 1, if 4 stones were previously removed from it).

The intended solution is to use dynamic programming with bitmasks to calculate the Grundy value for each pile size, state = (number of stones, mask), where mask represents the available moves.

However, I coded a simpler solution and got AC. The problem turned to be equivalent to taking a larger amount of stones at each step (Submission: 33990154). I don't fully understand this equivalence, and whether it's correct or not. Can anyone shed light on a formal proof for this?

Full text and comments »

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

By yelghareeb, history, 7 years ago, In English

Hello Codeforces community,

In problem D (Area of Two Circles' Intersection), I wanted to calculate the angle between two vectors.

I calculated the angle α using the dot and cross products of the vectors c1p1 (name it V1) & c1c2 (name it V2) using the following equation:

Then used the atan2 function to get the angle. I got a WA with a small precision drift in test 41. I changed the implementation to what was described in the editorial and calculated α using the low of cosines as follows:

where d is the distance between the centers of the circles. I used the acos function to get the angle, this passed the system tests.Those are the links of my submissions:

Wrong: http://codeforces.net/contest/600/submission/27546617
Correct: http://codeforces.net/contest/600/submission/27546673

I wonder why my first approach failed.

Another problem, Nearest Vectors:
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.

I sorted the vectors w.r.t their angles, then looped on them minimizing the value of angle[i + 1] — angle[i]. I wrote the following function to get the angle between each vector and the positive direction of the X-Axis

long double get_ang(pii coords) {  
  double res = atan2(coords.second, coords.first);  
  if (res < 0) res += 2 * PI;  
  return res;  
}  

This gave me WA in a test case 140, where 2 answers were very close in the difference. I modified the function and converted the angles to degrees and it passed.

long double get_ang(pii coords) {  
  double res = atan2(coords.second, coords.first) * 180 / PI;  
  if (res < 0) res += 2 * PI;  
  return res;  
}  

Wrong submission: http://codeforces.net/contest/598/submission/27534014
Correct submission: http://codeforces.net/contest/598/submission/27534469

I also wonder how this very slight modification affected the differences between angles.

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By yelghareeb, history, 8 years ago, In English

I’m going to share with you my story in today’s contest. After the system test and getting my A B C problems accepted, I was surprised of being removed from the standings board and having my problems skipped. Thanks to Mike Mirzayanov, I knew that there was a cheating incident on my profile, as my solution for problem A was identical to pashka921’s.

The 2 solutions are completely IDENTICAL and There is no probability that this situation happened by coincidence. FYI, his submission was before mine by 5 seconds exactly.

First, I’m going to prove that pashka921 is cheating:

  1. At every page of submission on his profile (http://codeforces.net/submissions/pashka921), there are some skipped problems, which means that it’s not the first time he cheated.

  2. In today’s contest, he made 2 submissions for problem A, with 2 TOTALLY DIFFERENT codes (he got a WA in the first one, and the second one was actually with my code and was accepted):

  1. By looking at other submissions that this person did, in codeforces round 367 div 2, between time 20:36:09 and time 20:40:13, he was able to make 2 submissions with two TOTALLY different codes, within a time interval of 4 minutes between both:
  1. These are not the ONLY weird cases found. You can check his profile, and you can spot them easily.

How was he able to submit my code?

During contests, I use the online editor www.ideone.com for coding. I just noticed after this incident that the code on ideone is made public by default, which is how this guy could have accessed my code. Those are the links for Problems A and C that I wrote during today’s contest: My problem C: http://ideone.com/ekrSy6 My problem A: http://ideone.com/qvPbwk

The code for problem A was available on ideone at 19:39:20 (You can open the source of the HTML page and search for “created” and spot the timestamp), so: Code was available on ideone at: 19:39:20 His submission at: 19:39:28 Mine at: 19:39:33

For my submission: http://ideone.com/qvPbwk, I am taking a screenshot of my browser to prove that I’m the OWNER of this code.

Notes: - Having the edit button means that I’m the owner of the code. - 19:39:20 is GMT+2

Just to sum up, this was my experience today. Please be careful whenever you use online IDEs during the contest, as your code may be exposed publicly.

Full text and comments »

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