You are not logged in. Please login at www.codechef.com to post your questions!

×

CHEFTWOS - Adhoc Approach

12
2

Rules for good string:

1) If at index i, the char is '1' and char at i-1 is '2', then char at i-2 should be '2'.

2) If at index i, the char is '2' and char at i-1 is '2', then char at i-2 should be '1'.

Algorithm:

1) Traverse the two input strings and check for the above two conditions.

2) If the conditions doesn't satisfy at index i, swap the chars of both strings at i.

3) Again if the conflict occurs at the same index, the ans is 0.

4) If the conditions are satisfied at all indexes, the answer is a power of 2.

Steps to calculate ans:

1) Count the no. of indexes at which the chars are same. Let this count be c.

2) There may be indexes at which the chars are not same. Count the pairs of such indexes. Let this count be p.

3) The ans is pow(2,c+p)

Code: https://www.codechef.com/viewsolution/11855552 Time: 0.03

asked 18 Oct '16, 22:30

kay_kay's gravatar image

4★kay_kay
1.2k721
accept rate: 20%

edited 20 Oct '16, 15:01

admin's gravatar image

0★admin ♦♦
19.8k350498541

simple and clear explanation :-)

(19 Oct '16, 13:35) abishek_kumar1★

i solved the same way 0.04 time ..nothing special about this question..just do what problem said. make good all work is done here.calculation is easy after anspection of a few test cases i guess.

(20 Oct '16, 13:31) mahipalsaran3★

Can you explain why does it work?

link

answered 20 Oct '16, 03:40

yougaindra's gravatar image

2★yougaindra
913
accept rate: 0%

Amazing explanation. I've looked over so many answers but haven't found any matching this level of clarity. Good job !

link

answered 16 Jan '18, 23:11

shivan111's gravatar image

2★shivan111
101
accept rate: 0%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×968
×20

question asked: 18 Oct '16, 22:30

question was seen: 1,654 times

last updated: 16 Jan '18, 23:11