CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Long 2012
    • May Cook-Off
    • May Long 2012
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » September 2009 (Contest VIII) » Alien language

Alien language

Problem code: G4

  • All Submissions

All submissions for this problem are available.

Aliens from the planet of Zrxllrlv have an extremely well-developed language. Recently they have introduced a special alphabet which consists of only 2 symbols. Now, they would like to develop a way to write down all the words they have in their language using this alphabet. They want to be able to decode sequences of words without breaks between them, so they would like to retain the following property: no word is the proper prefix of any other word. Knowing know how many words they have, that each word occurs equally often in every-day use, and knowing the effort required to write down each of the two symbols of the alphabet (the complexity of the first symbol and the second symbol need not to be equal!) help them to develop an encoding which minimizes the mean effort required to write down a word of the language.

Input

First, 1≤t≤10000, the number of test cases. Each test case contains: 1≤a≤109, 1≤b≤109, 1≤n≤1012, meaning: the effort required for writing down the first symbol, the effort required for writing down the second symbol, and the number of words of the language, respectively.

Output

For each testcase, output the total effort required to obtain all words in the optimal encoding.

Example

Input:
2
2 1 3
1 1 16
Output:
7
64

Explanation

The optimal encoding for the first testcase is:
'0','10','11'.
The optimal encoding for the second testcase is:
'0000','0001',...,'1110','1111'.


Author: admin
Date Added: 15-08-2009
Time Limit: 1 - 5 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

Shouldn't the output for the

gfosco @ 2 Sep 2009 12:21 AM

Shouldn't the output for the first test case be 5, based on the explanation?

No, the sum of the values is

admin @ 2 Sep 2009 12:26 AM

No, the sum of the values is 7 and not 5.

Does the empty string count

triplem @ 2 Sep 2009 08:08 AM

Does the empty string count as a word (ie is the answer 0 when n=1)?

 The o\p of 1st case sud be

rahul.mmec @ 2 Sep 2009 10:28 AM

 The op of 1st case sud be '00','10','11' instead of 0','10','11' due to absence of seperator in d alien`s language.

 

No, the explanation is

triplem @ 2 Sep 2009 01:03 PM

No, the explanation is correct as is.

@Stephen No.

admin @ 2 Sep 2009 01:55 PM

@Stephen No.

No, it means that your code

admin @ 2 Sep 2009 07:32 PM

No, it means that your code is producing the wrong answer for the test input.

  I want to write my code in

Aby @ 2 Sep 2009 07:55 PM

 

I want to write my code in C#. Can I read input from Console & write output to Console?

Either the answer for the

jdmetz @ 3 Sep 2009 02:02 AM
Either the answer for the first case should be 5 (lengths of 1, 2, and 2 sum to 5) or the problem statement should instruct us to output the total effort required to write every word rather than the total length of all encodings.

@Abhijeet Yes. @Josh Fixed.

admin @ 3 Sep 2009 03:18 AM

@Abhijeet Yes.

@Josh Fixed.

Shouldn't the optimal

philliplynx @ 3 Sep 2009 08:07 AM

Shouldn't the optimal encoding for the first test case be '00','10','11' ? 

/slightly confused. 

Can you please explain the

kamaltherocky @ 3 Sep 2009 11:56 AM

Can you please explain the output of the first testcase?

For the first test case, it

admin @ 3 Sep 2009 01:13 PM

For the first test case, it is the sum of the efforts for writing down the words mentioned in the explanation.

 

@Michael No

The largest output for this

myprasanna @ 3 Sep 2009 01:16 PM

The largest output for this problem exceeds a 64-bit integer. (a=b=1e9;n=1e12; since every word requires atleast one symbol to be output and 1e9*1e12 exceeds 64-bits);

I just want to ask here, if the judge expects the outputs to exceed 64-bits. Just a 'yes' would be good. Thanks.

Yes :)

admin @ 3 Sep 2009 01:32 PM

Yes :)

I apologize for leaving some

izulin @ 3 Sep 2009 09:42 PM

I apologize for leaving some doubts what is actual problem task, but sample test should leave no doubts...

i am new in here can someone

ankit_frenz @ 7 Sep 2009 01:31 AM

i am new in here can someone tell me what should be the input file name?

input.txt?

 

Read from standard input, not

triplem @ 7 Sep 2009 07:03 AM

Read from standard input, not from a file.


so if i use php..i need to

ankit_frenz @ 7 Sep 2009 12:29 PM

so if i use php..i need to create a form to sbmit data?

If yes the for should be one text box only?

Thanks

See this.

triplem @ 7 Sep 2009 01:09 PM

See this.

My code solves the problem in

keshav_57 @ 11 Sep 2009 11:08 AM

My code solves the problem in 2.5 seconds for the n of the order of 10^12 in my computer. I know there are quite a few correct submissions, but I'm still at a total loss because I cant see any reason why the code should time out on the judge.

The online judge is likely to

triplem @ 11 Sep 2009 12:01 PM

The online judge is likely to be slower than your computer due to the setup. See the FAQ for the full specs.

Other than that, don't forget there can be 10000 tests.. I presume your 2.5 seconds is the total for 10000 inputs of size 10^12?

Yes. I create 10000 tests

keshav_57 @ 11 Sep 2009 12:41 PM

Yes. I create 10000 tests where n <= 10^12.

For Smart Frog, the code that runs in 6 seconds on my computer gets accepted. Which means it took less than 3 seconds on the judge. Thats half the time!

Why should this one take more than double the time!

 

Anyways, I'll try and check

keshav_57 @ 11 Sep 2009 12:42 PM

Anyways, I'll try and check once more trough it, if there is a mistake on my side. Or if I can optimize a little more.

No idea why your smart frog

triplem @ 11 Sep 2009 12:47 PM

No idea why your smart frog solution runs slower on your computer; the judge here is always roughly twice the time it takes on my computer, so I use that as a guide.

would it be possible to get

jiesun2000 @ 11 Sep 2009 08:57 PM

would it be possible to get the test case and correct result for this problem.

thanks Admin

@earyoyo The test cases will

admin @ 13 Sep 2009 07:59 PM

@earyoyo The test cases will be uploaded soon.

hi, i ma new here... just

nandank81 @ 21 Sep 2009 07:32 AM

hi,

i ma new here...

just wanted to know how to  submit code.

 

regards,

nandan

Choose any of the problems

admin @ 21 Sep 2009 01:43 PM

Choose any of the problems from the practice section in the navigation panel and once you have written the code, click on the submit button on the top right and choose the language and then submit the code.

If I am understanding

dwitkowski @ 23 Sep 2009 11:32 PM
If I am understanding correctly, each word cannot be a substring of any other word (proper prefix) yet I still do not get how '0','10','11' was arrived at as a solution. First of all I would expect '00' and not '0'. Second, it seems to me that the inverse, '1','01','00' would satisfy the requirements just as well, so I really have no idea how an answer can be considered "optimal" other than arbitrarily.
I would rather not read the solution code as I would like to try and figure this out myself, but I am stumped before even starting. Might anyone enlighten me?

Part of my message was cut

dwitkowski @ 23 Sep 2009 11:43 PM

Part of my message was cut off. As I mentioned, I don't see how the first output is a valid solution over '1','01','00' and therefore how it was arrived at over the inverse.

1,01,00 is a valid

triplem @ 24 Sep 2009 06:30 AM

1,01,00 is a valid prefix-free encoding. Since it uses three 0s (weight 2 each) and two 1s (weight 1 each), the total weight is 8.

The total weight of 0,10,11 is 7, which is better.

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com