We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #244: Sliders

Project Euler #244: Sliders

Problem
Submissions
Leaderboard
Discussions

This problem is a programming version of Problem 244 from projecteuler.net

You probably know the game Fifteen Puzzle. Here, instead of field 4 by 4 and numbered tiles, we have field by , [] red tiles and [] blue tiles.

A move is denoted by the uppercase initial of the direction (Left, Right, Up, Down) in which the tile is slid, e.g. starting from configuration (S), by the sequence LULUR we reach the configuration (E):

(S) (E)
**(S)** **(E)**

For each path, its checksum is calculated by pseudocode:

...

where is the ASCII value of the -th letter in the move sequence and the ASCII values for the moves are:

Letter Code
L 76
R 82
U 85
D 68

For the sequence LULUR given above, the checksum would be .

Now, starting from given configuration (S), find all shortest ways to reach given configuration (E).

What is the sum of all checksums for the paths having the minimal length?

Input Format

First line contains the only integer .

Next lines contain configuration (S).

Next lines contain configuration (E).

Blue, red and white tiles are denoted by letters B, R and W respectively.

Constraints

Output Format

Print the only number the total sum of all checksums modulo .

Sample Input 0

2
WR
BB
RB
BW

Sample Output 0

18553

Sample Input 1

3
BBB
BWR
RRR
RBR
BWB
RBR

Sample Output 1

86665639

Author

yakutovd

Difficulty

Easy

Max Score

100

Submitted By

900

Need Help?


View discussions
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy