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

×

ENIGMA06 - Editorial

PROBLEM LINK:

Shyam and Raju

Author and Editorialist : Dhruv Mahajan

DIFFICULTY:

Simple

PREREQUISITES:

DP

EXPLANATION:

Store the occurance of A,B,C in a dp array.

Let, Ai = Number of ‘A’s in S between the indexes 1 and i (inclusive). Bi = Number of ‘B’s in S between the indexes 1 and i (inclusive). Ci = Number of ‘C’s in S between the indexes 1 and i (inclusive).

Let’s consider the substring Sj...i : Number of ‘A’-s in that substring = Ai - Aj-1 Number of ‘B’-s in that substring = Bi - Bj-1 Number of ‘C’-s in that substring = Ci - Cj-1

So for that substring to be good: Ai - Aj-1 = Bi - Bj-1 = Ci - Cj-1

Alternatively the following two conditions are enough for that substring to be good:

Ai - Bi = Aj-1 - Bj-1 Ai - Ci = Aj-1 - Cj-1

Find all the subtrings in two loops match the occurance of A,B,C from the dp array's.

SOLUTION:

Link to Solution

This question is marked "community wiki".

asked 16 Oct '15, 19:14

sumit.asr_128's gravatar image

2★sumit.asr_128
464
accept rate: 10%

edited 16 Oct '15, 23:26

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:

×15,643
×2,168
×1,173
×42

question asked: 16 Oct '15, 19:14

question was seen: 749 times

last updated: 16 Oct '15, 23:26