It is currently Sat May 10, 2025 2:13 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 47 posts ]  Go to page 1, 2, 3  Next
Author Message
Offline
 Post subject: Google Code Jam 2011
Post #1 Posted: Fri May 06, 2011 9:05 am 
Honinbo

Posts: 9552
Liked others: 1602
Was liked: 1712
KGS: Kirby
Tygem: 커비라고해
Google code jam will commence shortly:
http://code.google.com/codejam/

If you're interested in programming, these competitions are sometimes fun.

_________________
be immersed

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #2 Posted: Fri May 06, 2011 10:04 am 
Gosei
User avatar

Posts: 2116
Location: Silicon Valley
Liked others: 152
Was liked: 330
Rank: 2d AGA
GD Posts: 1193
KGS: lavalamp
Tygem: imapenguin
IGS: lavalamp
OGS: daniel_the_smith
Thanks, I think I'll give it a shot...

_________________
That which can be destroyed by the truth should be.
--
My (sadly neglected, but not forgotten) project: http://dailyjoseki.com

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #3 Posted: Fri May 06, 2011 11:48 am 
Lives in gote
User avatar

Posts: 643
Location: Munich, Germany
Liked others: 115
Was liked: 102
Rank: KGS 3k
KGS: LiKao / Loki
The two sample programs for the qualification round looked very easy to me. Parsing the input file is probably harder than solving the actual problem. So I guess I'll put in a few minutes tomorrow to solve them. No idea if I have the time/brain for the later rounds :P

_________________
Sanity is for the weak.

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #4 Posted: Fri May 06, 2011 1:23 pm 
Lives with ko
User avatar

Posts: 155
Location: The Netherlands
Liked others: 11
Was liked: 0
Rank: KGS 6 kyu
KGS: Sevis
I'm going to be participating, but seeing as my algorithms' complexity is usually best represented with up arrow notation, I doubt I'll get through the qualification rounds.

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #5 Posted: Fri May 06, 2011 3:40 pm 
Lives in gote
User avatar

Posts: 643
Location: Munich, Germany
Liked others: 115
Was liked: 102
Rank: KGS 3k
KGS: LiKao / Loki
The round 2 problems on the other hand are evil. I just tried last year's bacteria problem. Wrote by program, and it worked. The limits said that the initial configuration has at max 1M bacteria on a 1Mx1M field.
What they didn't say that the number of bacteria grows far beyond 100M in some of their testcases. Out of memory :( And once you have that testcase you just have 8 minutes to submit the solution.

_________________
Sanity is for the weak.

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #6 Posted: Fri May 06, 2011 3:56 pm 
Tengen

Posts: 4382
Location: Caldas da Rainha, Portugal
Liked others: 499
Was liked: 733
Rank: AGA 3k
GD Posts: 65
OGS: Hyperpape 4k
The qualification problems did look remarkably easy. Which is a way of saying that I think I might have had a chance at solving them.

_________________
Occupy Babel!

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #7 Posted: Sat May 07, 2011 3:42 am 
Lives in gote
User avatar

Posts: 499
Location: Germany
Liked others: 213
Was liked: 96
Rank: Fox 3D
GD Posts: 325
Is it only possible to see the problems via registering?

_________________
Stay out of my territory! (W. White, aka Heisenberg)

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #8 Posted: Sat May 07, 2011 7:55 am 
Gosei
User avatar

Posts: 2116
Location: Silicon Valley
Liked others: 152
Was liked: 330
Rank: 2d AGA
GD Posts: 1193
KGS: lavalamp
Tygem: imapenguin
IGS: lavalamp
OGS: daniel_the_smith
Yes, but you can see problems from prior events.

What are people's handles there? I'm lavalamp if you want to add me to your scoreboard. :mrgreen:

_________________
That which can be destroyed by the truth should be.
--
My (sadly neglected, but not forgotten) project: http://dailyjoseki.com

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #9 Posted: Sat May 07, 2011 1:37 pm 
Lives in gote
User avatar

Posts: 643
Location: Munich, Germany
Liked others: 115
Was liked: 102
Rank: KGS 3k
KGS: LiKao / Loki
Finally done. nick: CodeInChaos

My thoughts about Problem D:

Google = Image
I probably put more work into Problem D than into the rest together. F**ing trolled.

_________________
Sanity is for the weak.

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #10 Posted: Sat May 07, 2011 2:14 pm 
Gosei
User avatar

Posts: 2116
Location: Silicon Valley
Liked others: 152
Was liked: 330
Rank: 2d AGA
GD Posts: 1193
KGS: lavalamp
Tygem: imapenguin
IGS: lavalamp
OGS: daniel_the_smith
In two hours when it closes, please please please explain to me what rabbit trail you were following, it's driving me nuts. I was super extra careful on D, but only because I could see half the people were getting it wrong-- figured it was a trick question... What are people so commonly doing that is wrong? C was way harder, I thought.

...plus the large input for C triggered a condition in my parsing code that I didn't handle initially... that was fun, having to fix it with the clock running...

I looked at some of the questions for earlier round 1's-- I don't expect to make it to round two. Some people were submitting answers in the time it takes me just to read the problems... :/

_________________
That which can be destroyed by the truth should be.
--
My (sadly neglected, but not forgotten) project: http://dailyjoseki.com

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #11 Posted: Sat May 07, 2011 2:27 pm 
Honinbo

Posts: 9552
Liked others: 1602
Was liked: 1712
KGS: Kirby
Tygem: 커비라고해
I thought C was harder than D, as well. I actually ran out of memory on C :-p.

_________________
be immersed

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #12 Posted: Sat May 07, 2011 2:35 pm 
Gosei
User avatar

Posts: 2116
Location: Silicon Valley
Liked others: 152
Was liked: 330
Rank: 2d AGA
GD Posts: 1193
KGS: lavalamp
Tygem: imapenguin
IGS: lavalamp
OGS: daniel_the_smith
Kirby wrote:
I thought C was harder than D, as well. I actually ran out of memory on C :-p.


Really? Wow, we must have had completely different solutions...

_________________
That which can be destroyed by the truth should be.
--
My (sadly neglected, but not forgotten) project: http://dailyjoseki.com

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #13 Posted: Sat May 07, 2011 3:14 pm 
Honinbo

Posts: 9552
Liked others: 1602
Was liked: 1712
KGS: Kirby
Tygem: 커비라고해
My algorithm was kind of basic. I got a list of all permutations of the candy values for a particular set. Then, for each of those permutations, I split the set of candy values into two sets, drawing the line at (1, n-1), (2, n-2), etc.

For each of these set divisions, I took the bitwise XOR of the values in the sets, and saw if they were equal. If they were equal, I grabbed the real sum of the set, and kept track of the maximum.

This seemed to work for the sample input I used before trying to submit, but when I got a larger dataset, I had some memory errors due to some arraylist cloning that I was doing. I'm assuming there's either a bug in the code i wrote to get all of the permutations, or I'm doing something inefficient in that method.

I guess I could still work on the problem, as there's still time to investigate it, but I'm not too worried about it since you only need 25 points this round to qualify.

_________________
be immersed

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #14 Posted: Sat May 07, 2011 3:28 pm 
Lives in gote
User avatar

Posts: 643
Location: Munich, Germany
Liked others: 115
Was liked: 102
Rank: KGS 3k
KGS: LiKao / Loki
Kirby what's your nick there?

The majority seems to agree that ProbD is hardest. At least it has by far the least correct solutions.

_________________
Sanity is for the weak.


Last edited by Li Kao on Sat May 07, 2011 3:53 pm, edited 1 time in total.
Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #15 Posted: Sat May 07, 2011 3:33 pm 
Gosei
User avatar

Posts: 2116
Location: Silicon Valley
Liked others: 152
Was liked: 330
Rank: 2d AGA
GD Posts: 1193
KGS: lavalamp
Tygem: imapenguin
IGS: lavalamp
OGS: daniel_the_smith
Lol, after reading Kirby's description I realized that anyone reading my code for that problem is going to have a major WTF moment.

_________________
That which can be destroyed by the truth should be.
--
My (sadly neglected, but not forgotten) project: http://dailyjoseki.com

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #16 Posted: Sat May 07, 2011 3:36 pm 
Lives in gote
User avatar

Posts: 643
Location: Munich, Germany
Liked others: 115
Was liked: 102
Rank: KGS 3k
KGS: LiKao / Loki
Just noticed that the number 9 in the highscore is called "Weiqi" :)

_________________
Sanity is for the weak.

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #17 Posted: Sat May 07, 2011 4:00 pm 
Lives in gote
User avatar

Posts: 643
Location: Munich, Germany
Liked others: 115
Was liked: 102
Rank: KGS 3k
KGS: LiKao / Loki
I thought C was the easiest of all. At least I instantly had the right idea for it.
The broken adding is equivalent to binary xor. Then xoring all in A and xoring all in by and setting that equal is equivalent to xoring everything and setting it to zero. How you divide the among the heaps doesn't matter at all. You just need to make sure the heaps aren't empty, i.e. give the other guy the cheapest item.

B posed no problems either, it's just implementing the requirements.

And in A I had a stupid off-by-one error which lead to my two wrong submissions.

And problem D. I didn't realize that the number of items which aren't sorted yet equals the expectancy value. So I devised some complicated recursive memoizing algorithm. Fed the number of unsorted items into it. And it simply returned what I fed it with. T_T
My algorithm started with the number of items-to-sort, then calculated the individual probabilities for how probably each number of items-to-sort after the move is. Then there was the additional problem that no progress might be made at all, but I can't recurse without a change in parameters since that recurses infinitely. So I used the rule for geometric sums to fix it.

--------

Everything correct for me, Lavalamp lost 15 points.

_________________
Sanity is for the weak.

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #18 Posted: Sat May 07, 2011 4:13 pm 
Gosei
User avatar

Posts: 2116
Location: Silicon Valley
Liked others: 152
Was liked: 330
Rank: 2d AGA
GD Posts: 1193
KGS: lavalamp
Tygem: imapenguin
IGS: lavalamp
OGS: daniel_the_smith
OK, it's over now :)

I had a brain fart and got XOR mixed up in my head. On a related note, I now know how to do an XOR using bitwise or, and, and not.

My solution for C is like Kirby's, but:
* I used an array of bools to count off the permutations; a true in the array meant the number was in pile A, false meant it was in pile B. So, just one tiny allocation.
* I kept a sum and an XOR sum for each pile, every time I changed a bool I updated both piles.
* That's an O(2^N) algorithm, but it solved the first data set just fine (after I added the condition that neither pile be empty, duh).
* To solve the large data set, I added the optimization that if either pile XOR'd to 0 at any point, I can remove the whole pile from consideration and add its value to the largest equal pile. Then I noticed that if pile B ever XORs to 0, I'm already done.

I'm still not sure if there's a data set that could have broken this. I think that it can only "cancel out" groups of numbers with the same bits set-- I think with the numbers all less than 1e6, it will be fine.

_________________
That which can be destroyed by the truth should be.
--
My (sadly neglected, but not forgotten) project: http://dailyjoseki.com

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #19 Posted: Sat May 07, 2011 4:21 pm 
Lives in gote
User avatar

Posts: 643
Location: Munich, Germany
Liked others: 115
Was liked: 102
Rank: KGS 3k
KGS: LiKao / Loki
Both problem C and D become extremely short once you have the right idea.

Problem C:
Code:
int accu = 0;
int count = ReadLine().ToInt();
int[] values = ReadLine().Split().ToInt();
Debug.Assert(values.Length == count);

//xor all of them
foreach (int value in values)
   accu ^= value;

Write(CaseStr + " ");
if (accu != 0)
      WriteLine("NO");
   else
      WriteLine(values.Sum() - values.Min());//Take everything but the lowers item


Problem D:
Code:
int count = ReadLine().ToInt();
int[] initial = ReadLine().Split().ToInt();
Debug.Assert(initial.Length == count);
int wrong = initial.Where((v,i) => v != i + 1).Count();
WriteLine(CaseStr + " " + wrong.ToStringInv());


But how did you find the solution for Problem D? It's not obvious to me that the number of unsorted items equals the expected number of turns.

_________________
Sanity is for the weak.

Top
 Profile  
 
Offline
 Post subject: Re: Google Code Jam 2011
Post #20 Posted: Sat May 07, 2011 4:29 pm 
Gosei
User avatar

Posts: 2116
Location: Silicon Valley
Liked others: 152
Was liked: 330
Rank: 2d AGA
GD Posts: 1193
KGS: lavalamp
Tygem: imapenguin
IGS: lavalamp
OGS: daniel_the_smith
Li Kao wrote:
I thought C was the easiest of all. At least I instantly had the right idea for it.
The broken adding is equivalent to binary xor. Then xoring all in A and xoring all in by and setting that equal is equivalent to xoring everything and setting it to zero. How you divide the among the heaps doesn't matter at all. You just need to make sure the heaps aren't empty, i.e. give the other guy the cheapest item.


Ah, good point. If I'd realized it was an XOR maybe I would have noticed that. :oops:

Li Kao wrote:
And problem D. I didn't realize that the number of items which aren't sorted yet equals the expectancy value. So I devised some complicated recursive memoizing algorithm. Fed the number of unsorted items into it. And it simply returned what I fed it with. T_T
My algorithm started with the number of items-to-sort, then calculated the individual probabilities for how probably each number of items-to-sort after the move is. Then there was the additional problem that no progress might be made at all, but I can't recurse without a change in parameters since that recurses infinitely. So I used the rule for geometric sums to fix it.


Yeah, D was a math problem, not a programming problem... N * ((N-1)! / N!) = 1

Li Kao wrote:
Everything correct for me, Lavalamp lost 15 points.


Yeah, I just ran another large data set through it and it failed that one, too... hm...

_________________
That which can be destroyed by the truth should be.
--
My (sadly neglected, but not forgotten) project: http://dailyjoseki.com

Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 47 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group