Facebook Hacker Cup 2012 Qualification Round Auction Problem Solved

1. Alphabet Soup

Just use 8 counters to count the numbers of the key letters. The solution can be easily deduced by those values.
2. Auction
My approach is trying to construct a directed graph based on the ‘better’ relation. This graph constructed should be acyclic. Every root you found should be Bargain product. And every leaves should be Terrible Deal product. To save the computation time, I just used an ArrayList to model the computation mentioned above.
3. Billboards
I just use brute force method for this problem. The fontsize are reducing during the iteration.
To make the verification easier, I assume there is a cursor in the billboard. When I insert a word to the billboard, the cursor move. If the cursor goes outside of the billboard, I reset and try another iteration with a smaller fontsize.
Compile/Run Programs Online at http://ideone.com/ideone/Index/submit/



Auction was by far the most difficult problem in the qualification round, with only 28 correct solutions. Solving the task efficiently required a few key observations. First of all, note that bargains and terrible deals are completely symmetrical under transformation P’ = M + 1 – P, W’ = K + 1 – W. Therefore we only need to consider the bargains part of the problem.


If the product is a bargain, it has minimum weight among all products with the same price. Since the constraints on K and M are relatively low (at most 107), it’s possible to keep track of the product with minimum weight for each particular price and to consider only these products in the rest of the solution. Also we should account for products with the same weight and price by keeping the number of times each minimum occurs among products.


Let’s assume that these minimum weights have already been calculated. Then in order to find all bargains we have to loop through all potential products in the order of increasing price, maintaining current minimum of weight. If the next product weights less than the current minimum, then it is in fact a bargain. By explicitly calculating the weight and price of each product using the formulas given in the statement and calculating the minimum weight for each price, we can get a solution that works in O(N) time. Unfortunately, N might be pretty big and this solution therefore won’t run in less than 6 minutes.


In order to speed up the solution, we have to notice that because of pseudorandomness the sequences of prices and weights are periodical, maybe except for some small number of products in the beginning of the sequence. Even though the full period of both product properties may be as large as K*M, we can take advantage of the separate periods for price and weights. First, we process the non-periodic part of the product sequence and determine the periods of prices and weight — let them be periodP and periodW. Consider all products that have price Ps, s < periodP. These are products with indexes s + i * periodP, i = 0,1,..,floor((N-s) / periodP)-1, let’s call this set Bs. The respective weights of products in Bs are W(s + i * periodP) mod periodW. Now consider products in B(s + periodP) mod periodW. They all have the same price and the sequence of weights is the same as for Bs starting from the second element. Thus if we write down the cycle of weights { W(s + i*periodP) mod period W, i = 0,1,2,…} then weights of products in Bx appear as a continuous subsequence in this cycle. We want to find the minimum value in each of these subsequences. Moreover, the number of elements in Bs for different s may differ at most by 1. This is a well-known Sliding Range Minimum Query problem that can be solved in linear time. If periodP is not prime we may need to consider several such cycles in order to cover all possible weights of products.


This way, minimum weights for each price can be found simultaneously for all prices in time O(periodP+periodW). It’s not hard to add proper bookkeeping to handle repeating products with the same price and weight. Overall the solution has a complexity of O(K+M).

Facebook Hacker Cup 2012 Qualification Round Billboards Problem Solved

We are starting preparations for Hacker Cup 2013 really early. Our first step is to prepare billboards to advertise the contest. We have text for hundreds of billboards, but we need your help to design them.

The billboards are of different sizes, but are all rectangular. The billboard widths and heights are all integers. We will supply you with the size in inches and the text we want printed. We want you to tell us how large we can print the text, such that it fits on the billboard without splitting any words across lines. Since this is to attract hackers like yourself, we will use a monospace font, meaning that all characters are of the same width (e.g.. ‘l’ and ‘m’ take up the same horizontal space, as do space characters). The characters in our font are of equal width and height, and there will be no additional spacing between adjacent characters or adjacent rows.

Let’s say we want to print the text “Facebook Hacker Cup 2013″ on a 350×100″ billboard. If we use a font size of 33” per character, then we can print “Facebook” on the first line, “Hacker Cup” on the second and “2013” on the third. The widest of the three lines is “Hacker Cup”, which is 330″ wide. There are three lines, so the total height is 99″. We cannot go any larger.


The first line of the input file contains a single integer T: the number of test cases. T lines follow, each representing a single test case in the form “W H S”. W and H are the width and height in inches of the available space. S is the text to be written.


Output T lines, one for each test case. For each case, output “Case #t: s”, where t is the test case number (starting from 1) and s is the maximum font size, in inches per character, we can use. The size must be an integral number of inches. If the text does not fit when printed at a size of 1″, then output 0.


  • 1 ≤ T ≤ 20
  • 1 ≤ W, H ≤ 1000
  • The text will contain only lower-case letters a-z, upper-case letters A-Z, digits 0-9 and the space character
  • The text will not start or end with the space character, and will never contain two adjacent space characters
  • The text in each case contains at most 1000 characters

[Java] Billboards – Pastebin.com



Billboards had the second-most correct solutions in the qualification round, with 3210 correct submissions. The maximum size of the billboard was 1000×1000, so checking every possible font size is efficient enough. We start with the smallest possible font size, 1, and test each higher size until we find a font size that doesn’t fit the sign. For each font size, convert the dimensions of the billboard into rows and columns by taking the floor of the dimension divided by the font size. Then lay out the words from the first row to the last, putting as many words as possible onto each row.


Here’s a solution in Python:

import sys

cases = sys.stdin.readlines()

def solve(width, height, words):

for size in range(1, 1 + max(width, height)):

cols, rows = width // size, height // size

w = list(reversed(words))

r, c = 1, 0

while w:

c = len(w.pop())

if c > cols:

# word is too wide to fit on this line

return size – 1

while w and not (c + 1 + len(w[-1]) > cols):

c += 1 + len(w.pop())

if not w:

# We fit everything, check the next larger font size


r += 1

if r > rows:

# Too tall

return size – 1

c = 0



for case in range(1, len(cases)):

data = cases[case].split()

w, h = int(data[0]), int(data[1])

words = data[2:]

print “Case #{}: {}”.format(case, solve(w, h, words))

“If I Die” App allows you to post to Facebook only go up after you pass away

An app called “If I Die” has been released, which lets you post updates to Facebook which will only go up after you pass away. To have the update go up, three designated friends need to verify the update. According to CBS, the app has faced mixed reviews on the social network with some users finding it inappropriate, while others saying that it’s something that is needed. One user said that a lot of people pass away without saying certain things to people that might be important. Another user said that there may be some people who are terminally ill who would like to leave a message behind.

How to Improve your blog – 5 ways

What does it take to move your blog up to the next level? Obviously you need a regular supply of useful content to attract readers and keep your audience happy, but here are a few extra tips on increasing interest in your blog in 2012.

1. Stop Auto-Posting

2. Use Fewer Ads

3. Master Google Custom Search

4. Minimize the Panda Impact

5. Explore Additional Mediums

Read Details…

Download Marathi Edition Kalnirnay 2012 Calender Free Pdf download .pdf

Kalnirnay 2012  Marathi, Hindi, English free pdf download


Also See…

Gujarati Panchang 2012