CF296B.Yaroslav and Two Strings

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that s__i > w__i and s__j < w__j. Here sign s__i represents the i-th digit of string s, similarly, w__j represents the j-th digit of string w.

A string's template is a string that consists of digits and question marks ("?").

Yaroslav has two string templates, each of them has length n. Yaroslav wants to count the number of ways to replace all question marks by some integers in both templates, so as to make the resulting strings incomparable. Note that the obtained strings can contain leading zeroes and that distinct question marks can be replaced by distinct or the same integers.

Help Yaroslav, calculate the remainder after dividing the described number of ways by 1000000007 (109 + 7).

雅罗斯拉夫认为,两个由数字组成的、长度均为 nn 的字符串 ss 和 ww 是不可比较的,当且仅当存在两个下标 ii 和 jj(满足 1≤i,j≤n1 \le i, j \le n),使得 si>wis_i > w_i 且 sj<wjs_j < w_j。其中符号 sis_i 表示字符串 ss 的第 ii 个数字,类似地,wjw_j 表示字符串 ww 的第 jj 个数字。

一个字符串的模板是指由数字和问号("?")组成的字符串。

雅罗斯拉夫有两个长度均为 nn 的字符串模板。他希望计算:将这两个模板中所有问号均替换为某些数字(0–9)后,使得所得两个字符串不可比较的方案总数。注意:所得字符串可以包含前导零,且不同的问号可以被替换为相同或不同的数字。

请帮助雅罗斯拉夫计算该方案总数对 10000000071000000007(即 109+710^9 + 7)取模的结果。

输入格式

The first line contains integer n (1 ≤ n ≤ 105) — the length of both templates. The second line contains the first template — a string that consists of digits and characters "?". The string's length equals n. The third line contains the second template in the same format.

第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)——两个模板的长度。
第二行包含第一个模板——一个由数字和字符 ? 组成的字符串,其长度为 nn。
第三行以相同格式给出第二个模板。

输出格式

In a single line print the remainder after dividing the answer to the problem by number 1000000007 (109 + 7).

在一行中输出该问题答案对 10000000071000000007(即 109+710^9 + 7)取模后的余数。

输入输出样例

  • 输入#1

    2
    90
    09

    输出#1

    1
  • 输入#2

    2
    11
    55

    输出#2

    0
  • 输入#3

    5
    ?????
    ?????

    输出#3

    993531194

说明/提示

The first test contains no question marks and both strings are incomparable, so the answer is 1.

The second test has no question marks, but the given strings are comparable, so the answer is 0.

第一个测试用例中不含问号,且两个字符串不可比较,因此答案为 1。

第二个测试用例中不含问号,但给定的两个字符串可比较,因此答案为 0。

输入解题思路,AI测评打分。不知道怎么写?

首页