Advertisement blocking software were detected ;( Please add this webpage to whitelist.

ABCD - Colours A, B, C, D

no tags 

Consider a table with 2 rows and 2N columns (a total of 4N cells). Each cell of the first row is coloured by one of the colours A, B, C, D such that there are no two adjacent cells of the same colour. You have to colour the second row using colours A, B, C, D such that:

• There are exactly N cells of each colour (A, B, C and D) in the table.

• There are no two adjacent cells of the same colour. (Adjacent cells share a vertical or a horizontal side.)

It is guaranteed that the solution, not necessarily unique, will always exist.


[a natural number N ≤ 50000]

[a string of 2N letters from the set {A, B, C, D}, representing the first row of the table]


[a string of 2N letters from the set {A, B, C, D}, representing the second row of the table]













hide comments
darkhire21: 2015-10-18 11:00:37

read carefully statement 1 ..!!!!

(Tjandra Satria Gunawan)(曾毅昆): 2015-08-02 04:25:08

Finally AC, it's hard to think the solution but very easy to implement :)

Shubhransh Srivastav: 2015-07-09 17:10:53

wa on running judge 18.... don't know why :(

Last edit: 2015-07-13 19:30:43
Diksha Jaiswal: 2015-06-04 07:37:37

tle with backtracking :(

Aman: 2015-05-30 20:23:24

I think all possible permutations are not considered in the solution that's why its giving wrong ans on 18th test case... can any tell me what is 18th case.I have tried all possible test cases...can't find the error....

CoNtRaDiCtIoN: 2015-05-27 12:31:32

awesome problem :)

Rajat (1307086): 2015-03-28 00:56:52

There are several solutions, but if you apply the correct logic you will get one and only one.
Nice problem indeed.

chamini2: 2015-02-13 23:46:34

It's not test 18, it's wrong answer in general.

Malinga: 2014-12-25 16:23:20

Getting wrong answer in 18th test case...any suggestions please ??

Anubhav Balodhi : 2014-12-18 14:10:04

got AC, after lot of tries :-)

Added by:Adrian Satja Kurdija
Time limit:0.190s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel Pentium G860 3GHz)
Resource:originated from a mathematical problem