#DSU0000046. Gán chữ cái thành chữ số (Digit Assignment)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Gán chữ cái thành chữ số (Digit Assignment)
Digit Assignment
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Two records describe the same positive integer containing exactly digits. Each record is a string of length containing digits 0–9 and uppercase letters A–Z representing unreadable digits.
Assign a digit from to to each letter that appears. Every occurrence of the same letter, in either record, must receive the same digit. Different letters may receive the same digit. Existing numerical characters must remain unchanged.
After replacement, the two records must become exactly the same digit string, and the first digit must not be 0 so that it represents an -digit positive integer. At least one valid assignment is guaranteed. Count the number of distinct integers obtainable, not the number of letter assignments when several assignments produce the same integer.
Input
Line 1 contains ; lines 2 and 3 contain , each of length , using only 0–9 and A–Z.
Output
Print the count of valid -digit positive integers. The result may exceed 32-bit integers.
Subtasks
- Subtask 1 (20 points): ; ; characters belong to
0–9orA–Z; at least one valid assignment exists. - Subtask 2 (30 points): ; ; characters belong to
0–9orA–Z; at least one valid assignment exists. - Subtask 3 (50 points): ; ; characters belong to
0–9orA–Z; at least one valid assignment exists.
Examples
Input
3
XXX
YYY
Output
9
Explanation
Letters X and Y must represent the same digit, which cannot be zero in the first position: 9 possibilities.