Cryptarithm?!
Time limit1sMemory limit128 MB
Given three letter strings A+B=C, decide whether some assignment of distinct digits to letters makes the addition valid, columns up to 18 long.
- Level
Hard9 of 10
- Topics
- Backtracking, Math, Combinatorics, Brute force
- Solved
- No attempts yet
Problem
Cryptarithm is a mathematical puzzle in which each digit of a calculation is replaced by a letter, and the solver must recover which digit each letter stands for.
A well known instance is .
SEND
+ MORE
------
MONEY
Setting , , , , , , , satisfies the equation.
9567
+ 1085
------
10652
Given a cryptarithm written with three words, determine whether any digit assignment satisfies it.
The same letter always maps to the same digit, and different letters map to different digits. Numbers may start with .
Input
Three words , , are given, separated by spaces. They state that adding the first word and the second word yields the third word.
Each word consists only of uppercase English letters with no spaces, and each word is at most characters long.
Output
Print on one line if any satisfying assignment exists, and otherwise.
Hint
There can be many solutions, only existence matters. The input admits solutions, including and .