CF895D.String Mark
提高+/省选-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
At the Byteland State University marks are strings of the same length. Mark x is considered better than y if string y is lexicographically smaller than x.
Recently at the BSU was an important test work on which Vasya recived the mark a. It is very hard for the teacher to remember the exact mark of every student, but he knows the mark b, such that every student recieved mark strictly smaller than b.
Vasya isn't satisfied with his mark so he decided to improve it. He can swap characters in the string corresponding to his mark as many times as he like. Now he want to know only the number of different ways to improve his mark so that his teacher didn't notice something suspicious.
More formally: you are given two strings a, b of the same length and you need to figure out the number of different strings c such that:
-
c can be obtained from a by swapping some characters, in other words c is a permutation of a.
-
String a is lexicographically smaller than c.
-
String c is lexicographically smaller than b.
For two strings x and y of the same length it is true that x is lexicographically smaller than y if there exists such i, that _x_1 = _y_1, _x_2 = _y_2, ..., x__i - 1 = y__i - 1, x__i < y__i.
Since the answer can be very large, you need to find answer modulo 109 + 7.
在拜特兰国立大学,成绩是长度相同的字符串。若字符串 y 在字典序上严格小于 x,则称成绩 x 优于 y。
最近,拜特兰国立大学进行了一次重要的测验,瓦夏获得了成绩 a。教师很难记住每位学生的精确成绩,但他知道一个成绩 b,使得所有学生的成绩均严格小于 b。
瓦夏对自己的成绩不满意,因此决定提升它。他可以对自己成绩对应的字符串任意多次交换字符。现在,他只想知道:有多少种不同的方式能提升自己的成绩,使得教师不会察觉任何可疑之处。
更准确地说:给定两个等长的字符串 a 和 b,你需要计算满足以下条件的不同字符串 c 的数量:
-
c 可通过对 a 中的字符进行若干次交换(即重排)得到,换言之,c 是 a 的一个排列;
-
字符串 a 在字典序上严格小于 c;
-
字符串 c 在字典序上严格小于 b。
对于两个等长的字符串 x 和 y,若存在某个下标 i,使得 x1=y1,x2=y2,…,xi−1=yi−1,且 xi<yi,则称 x 在字典序上小于 y。
由于答案可能非常大,请输出答案对 109+7 取模的结果。
输入格式
First line contains string a, second line contains string b. Strings a, b consist of lowercase English letters. Their lengths are equal and don't exceed 106.
It is guaranteed that a is lexicographically smaller than b.
第一行包含字符串 a,第二行包含字符串 b。字符串 a 和 b 仅由小写英文字母组成。它们的长度相等,且不超过 106。
保证 a 的字典序小于 b。
输出格式
Print one integer — the number of different strings satisfying the condition of the problem modulo 109 + 7.
输出一个整数——满足题目条件的不同字符串的个数对 109+7 取模的结果。
输入输出样例
输入#1
abc ddd
输出#1
5
输入#2
abcdef abcdeg
输出#2
0
输入#3
abacaba ubuduba
输出#3
64
说明/提示
In first sample from string abc can be obtained strings acb, bac, bca, cab, cba, all of them are larger than abc, but smaller than ddd. So the answer is 5.
In second sample any string obtained from abcdef is larger than abcdeg. So the answer is 0.
在第一个样例中,从字符串 abc 可以得到字符串 acb、bac、bca、cab、cba,它们均大于 abc 但小于 ddd。因此答案为 5。
在第二个样例中,从 abcdef 得到的任意字符串均大于 abcdeg。因此答案为 0。
输入解题思路,AI测评打分。不知道怎么写?