Monday, February 8, 2010

The legend of Georgian ACM movement

The acronym "ACM" stands for the Association for Computing Machinery, which conducts the annual ACM International Collegiate Programming Contest, or simply ACM ICPC. This competition is widely recognized as the world championship, and its rules, possibly with mild alterations, are often used in other programming contests.

In general, the ACM rules suggest the following. The teams composed of one to three persons are provided with a set of mathematically-oriented problems and should code the solutions in one of the available languages. Upon writing the code, a team sends it to the server for evaluation on a set of testcases. Now, if the solution outputs the right answers in the time allotted and does not misperform in any way, the problem is marked as solved. Otherwise, the submission is rejected. Finally, the teams are ranked by the number of solved problems and by "penalty time" in case of ties, the latter depending on the number of wrong tries and solving time for each solved problem.

The contests which use the ACM rules are often referred to as ACM-style contests, and since they comprise the majority of the contests around, our whole activity can be called "The ACM movement".

I'm not sure about the exact birthdate of Georgian ACM movement but it's possibly around year 1999, when Tbilisi State University team participated in NEERC (the ACM ICPC semifinals region where Georgian teams participate) for the first time. For the next four years, the results have been stable but middling. The breakthrough came in 2004, when the TSU team, comprised of Nika Jimsheleishvili, Irakli Khomeriki and Revaz Khurtsilava, was just a problem away from the finals. Nika soon became the leader amongst domestic participants and his team fought every year to advance to the Finals. After a couple of line-up changes, the team Triumvirate with Nika, Giorgi Lekveishvili and me finally made it in 2008/2009 season.

You probably recognize all the names in the previous paragraph. There are several other people also worth mentioning when speaking about Georgian ACM movement, but this time I'd like to focus on one person instead. The person from whom I learned a lot in my olympic youth. The person who brought a lot into Georgian olympiads but never got the deserved credits. So, may I introduce the concealed legend of Georgian ACM movement - Davit Rachvelishvili aka rachvela.


I'll recall some of Davit's accomplishments, just to show you the whole picture. First of all, Davit was the first Georgian competitor on Topcoder and it was him who familiarized the rest of us with this truly helpful community. One can hardly overestimate the bonuses of Topcoder, including editorials and regular SRMs (which were far more regular in those distant times).
Davit also was the first of us to discover some algorithmic concepts which are extensively used in the contests nowadays - for instance, minimum cost maximum flow and fenwick trees.
Moreover, Davit was always willing to share his knowledge and help the fellow colleagues. Davit's easy temper and spiteless attitude were the perfect qualities for this. Sounds like an extract from a reference letter? Yep, but still maximally close to the truth ;)

Now let me tell about rachvela's way.

Chapter 1. The early years.
One might think that succeeding in programming, especially at the olympiads, is impossible without serious math and computer background from the very childhood. Now I'm telling you it's possible, since I have an example right before my eyes.
Davit never studied in a math-oriented school. He didn't bother studying at the normal one, either. Instead, he spent his adolescence breakdancing and hip-hopping (if you got the impression that he never went to school, that's false, he formally did). He still raps his self-written song from time to time, but his breaking will never be the same :D


Chapter 2. Engaging into olympiads.
When I was in eleventh grade, which was the final year in Georgian schools back in those times, I've set myself an objective of making it to the Georgian IOI team that year. So I worked hard and tried to participate in every contest that I found out about. UVA online judge hosted plenty of contests and I competed in the most of them. That was where I first encountered Davit. Soon, we also met at forum.ge and communicated this way for a long time. Davit was a freshman at Tbilisi State University and studied programming as diligently as me.

Now it's time for you to ask, hey, how did the break-boy leave the streets and find the aspiration for programming? Well, my friends, I doubt that there was any magic involved. Davit just grew up and found the occupation that was profitable, perspective and - the last but not the least - the occupation he liked. And once he found it, he did not stand back because of lack of knowledge or anything - he believed he's capable and he was going for it.


By the time when I joined TSU in 2005 (after failing the IOI team selection contests), Davit already was the leader of the university's second team. I also got on this team in early 2006 and we have competed together for several months, but had to break up before the start of the new season, since Davit went to the first team alongside Nika Jimsheleishvili and Giorgi Lekveishvili.

Chapter 3. The years of fame.
The first olympiad in which the new-formed first team took part was the All-Ukrainian Open Olympiad in Vinnytsia. This trip brought them the bronze medals of Ukrainian championship.

The next, and main, competition was NEERC 2006. We all pinned high hopes on the first team and believed it would advance to the Finals this time. Unfortunately, due to a malfunction of their machine (which was not properly compensated by the judges!) they lost a significant amount of time (and determination, I guess) and eventually finished 15 places behind the advancers.


The same team earned the first degree diplomas at the first Vekua Cup in April 2007. Davit was also granted the third degree diploma in the individual competition.

The last event where this team participated was KPI Open. The site stubbornly doesn't show the results for years before 2008, so I have to rely on my poor memory, which tells me that the boys took the third place then.


Since Nika had decided to skip the 2007/2008 ACM season, the teams reorganized again. Davit and Giorgi resurrected Irakli Khomeriki and began another advance-to-finals campaign. It was Davit's final year in baccalaureate and he wasn't going to pursue the Masters right away, so it was also his last chance to participate in ACM (because there also is a restriction on age and he would outgrow it). The team prepared thoroughly and was highly determined. However, eventually it all went completely wrong. Some really lame mistakes kept the first team well under the advancers zone. For Davit, the ACM Finals would remain a distant dream.

After the described events Davit quit programming contests, graduated from the university and fully concentrated on the job. We rarely heard of him in the course of the year and everybody, including him I think, thought his olympic career was over...

Chapter 4. The return of the Jedi.
...but we all were wrong. After having a year-long break, Davit entered The Georgian University of Saint Andrew the First-Called and, maybe inspired by Triumvirate finally advancing to the Finals and earning the Bronze medals, maybe just following the calling inside him, returned to the world of olympiads with all the diligence he had before.

The fortune did not turn its back on Davit, and he was granted permission to participate in ACM ICPC for one last season (the rules concerning the age were softened). His teammates were Avto Rukhadze, quite an experienced contestant, and Tornike Benidze, a debutant in ACM competitions. Hoping to advance to the Finals from NEERC in this situation would be barefaced impudence (those of you who ever took part in NEERC should understand). So the real fight was for the title of Champion of Georgia.

There were at least two teams from Tbilisi State University which were ought to beat Davit's in the domestic run - Tbilisi SU1 with ACM ICPC and IOI bronze medalist Giorgi Lekveishvili and IOI medalists Giorgi Nadiradze and Davit Tvalchrelidze, and Tbilisi SU2 composed of Giorgi Saghinadze, Andrew Lutsenko and Akaki Mamageishvili - this was their third successive season as a team, and they were quite serried.

But Davit managed to surprise us all. In a difficult contest, he managed to get the team on the top of Georgian teams ranklist, thereby finishing his ACM ICPC performances with the domestic Champion title and the head held high. An interesting thing is that both TSU teams named above lost to Tbilisi SU3 comprised of first-year students Zurab Kutsia, Nika Gabisonia and Beka Barbakadze. It's nice that the youth still keeps coming :)

Chapter 5. Epilogue.
So, I told you the story of Davit Rachvelishvili, one of the key figures in Georgian ACM movement evolution. You might ask me, what is he doing now?

Davit works as developer at JSC Georgian Card, where he performs stuff of all different sorts. He keeps claiming that Java is not an inch slower than C++, loves the Twilight Saga and still does not listen to metal.

Recently, Davit married his beloved Teo. You can look at the picture of the happy couple :)


And finally, even though ACM ICPC is definitely in the past, there are many other contests worth winning. And Davit knows that :) He still battles on Topcoder and is going to kick some asses at the next Google Code Jam. Moreover, Davit, Giorgi Lekveishvili and me are going to participate in Challenge 24 as Narwhals. Should be fun :)

Friday, January 22, 2010

SRM 459

It's been almost a year since my first and almost half a year since my last SRM, and I felt like making another one. So somewhen before the New Year I processed the ideas whirling in my head, wrote several problems and was offered the 459-th Single Round Match.

Div2 Easy - RecursiveFigures. The problem featured some eighth-grade level geometry, which, even with all the formulas in the statement, appeared to be not too easy (I guess there is nothing too easy for D2-250). The most interesting thing about it are the pictures by Lela Latsoshvili, who will be saving all of you from my mspaint-made illustrations from now on (I hope :D).

Div2 Medium / Div1 Easy - Inequalities. This problem can be solved in a number of ways, the most general of which has performance complexity of O(NlogN), where N is the number of inequalities, and can even produce the whole optimal intervals of values. However, since this is D1-Easy, the common solution to seek for is some neat brute force. With constraints as low as 1000, one could iterate over all possible values from -1 to 1001 with step 0.5 and check the answer for each of them - which is quite easy if you parse the input properly.

Div2 Hard - ParkAmusement. At first, the problem was deemed as too hard for Division 2, since it involved conditional probability - quite an uncommon topic for the second division. Even after the addition of thorough annotations, the tester still suggested to remove the conditional probability part - but I believed in Division 2, and Division 2 did not let me down. 24 successful submissions even made this my easiest D2-Hard yet. Not that I complain about it :) The key idea of the solution is that the probability of landing X being the starting landing is the ratio of (the probability of reaching an exit from X in K pipes) and (the probability of reaching an exit from any landing i in K pipes). Computing this probabilities is performed with dynamic programming, where the state is pair(landing, pipes left).

Div1 Medium - NumberPyramids. So, we have another problem featuring Lela's illustrations in place of my crooked landscapes. Though this time the problem itself can at least compete with its corresponding pictures. I was a little surprised with the high number of successful submissions for this problem, since its solution took me more efforts than, say, the SRM443's BinaryFlips. When I am not as sleepy as now at 3:30AM, I'll put the idea of the solution here.

Div1 Hard - TheContest
. Actually, at first I proposed another problem for this slot. However, it finally turned out to be way too hard, so I have modified my easiest problem from Vekua Cup Individual Contest's problemset - problem G, and suggested to use it. Unfortunately, eventually nobody solved it (though we were a lot more optimistic before the match).
The solution for the problem is as follows. First, let us consider N<=M. It's provable that if we have several rows already filled, then we always can fill the rest in spite of exactly how we've filled the previous rows. Therefore, the problem reduces to filling a row in a way not to conflict with already filled rows. For each position, let us try every number (which was not used in this column before) in ascending order. If it is possible to arrange the rest of the numbers in the columns to the right, then we take this number. And this possibility can be checked with the help of matching techniques: if we build a bipartite graph with the left-side nodes corresponding to columns and right-sides corresponding to numbers left, and the edge between left-side i and right-side j denoting that j was not used in i-th column, there must exist a maximum matching in this graph for the number to be feasible.
When N>M, we encounter a little problem. It is no longer true that we can fill the rows not thinking about the next ones. For example, for N=3 and M=2, filling the rows in this manner will give us {"12","21"} and the third row will be no longer fillable. It's easy to notice that every value must be used in the whole matrix a total of MIN(N,M)=M times. Therefore, an obvious restriction on the numbers to use is: if there is a number X such that if you don't use it in this row, then you won't have enough rows to use it a total of M times, you should use X in this row. A much less obvious thing is that this is also sufficient to fill the whole matrix row-by-row. So, for each row we should first identify all the values which have to be used in it and then fill this row, making sure that these values are used. But how to deal with this in the matchings we use to determine feasibility? Since augmenting paths in matchings never change the nodes matched (just edges), it's enough to perform all the augmentations for those must-use values and then match the rest of the columns to some of the values.
So, this is it. I still believe the targets just had a bad day, or the problem wouldn't stay virgin.

Alright, here is the round overview and that's all for now.

Friday, January 1, 2010

The red-colored New Year

So, the year 2009 is over. First of all, let me wish you all a happy and successful year 2010.

The previous year saw by far the greatest results of Georgian programming olympiads movement in whole and me in particular, the quintessence of which were the Bronze Medals at ACM ICPC 2009. But let me recollect them all in chronological order.

So, January began with two Topcoder SRMs prepared by Georgian writers - first of them by nika and the second by my very self. These were the first (at least as far as I know) international-level competitions with problemsets written by Georgians.

Our problemsetting experiment continued soon after at Winter Programming School in Kharkiv in February. The sixth day of the School was fully prepared by our team Tbilisi SU Triumvirate (Bogdanov, Jimsheleishvili, Lekveishvili) and its coach Temuri Zarkua. Also, we finished second in the overall raiting of the School.

Then, April came and we went to Stockholm in our quest for Georgia's first medals at ACM ICPC Finals. And the debut was really successful :)


Soon after the Finals, George also conducted his first SRM, and I had another two (440, 443).

Well, what else was there? In the end of June, George and me took the third place at KPI Open 2009. In September, I wrote the problemset for Vekua Cup 2009 Individual Competition. In November, Eduard and me took the second place at Open South Caucasian Championship 2009, the team Tbilisi SANGU 1 (Benidze, Rachvelishvili, Rukhadze) won the title of Champion of Georgia for the first time, and Nika took the sixth place at Google Code Jam Finals.

And now, for those of you who think 'What the hell is that red thing in the title', let's get to the final part of this post and my olympic year - my Topcoder rating. I firmly announced somewhen in Autumn that I would meet the New Year with red color at Topcoder, which means getting one's rating over 2200. I changed my handle from eyler to gojira_tc (simply gojira was already taken :|) and kept repeating that the new handle would only look good in red color. In the meanwhile, my rating graph kept falling and climbing, and finally December came with me still hanging close to the cherished line. I took the 11th place at the next-to-last SRM of the year and came closer to red than ever and was looking forward to the last SRM.

The last match of the year was on 6:00AM by Georgian time. Moreover, I had been celebrating the coming holidays on the evening of the previous day. So nothing really assumed that I would manage to keep my word, but still I decided to try. After performing decently in the coding phase, I was around the 50th place, which would guarantee a sufficient rating increase. However, I've made a couple of successful challenges, and looking at the division summary again, was utterly surpirsed, seeing my handle at the 5th place. The thing that surprised me even more was my score - 666 points. I decided to stop any challenge activity and keep the score. I found a code which was failing - at least I was sure I had the proper testcase. But I forced myself to leave it alone. After the testing, my position changed to #3, making it my best performance ever and giving me an unconditional red color. I saw that the code I thought was wrong actually passed the system test, which means I would spoil my great result if I tried to challenge it. Therefore, 666 points saved me.

So, now you can see my red-colored handle and complacent mug. As for me, I am going to take my friends to khinkali as a tribute to the forces which assisted me with their 666 points.