CF1120B.Once in a casino

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

One player came to a casino and found a slot machine where everything depends only on how he plays. The rules follow.

A positive integer aa is initially on the screen. The player can put a coin into the machine and then add 11 to or subtract 11 from any two adjacent digits. All digits must remain from 00 to 99 after this operation, and the leading digit must not equal zero. In other words, it is forbidden to add 11 to 99, to subtract 11 from 00 and to subtract 11 from the leading 11. Once the number on the screen becomes equal to bb, the player wins the jackpot. aa and bb have the same number of digits.

Help the player to determine the minimal number of coins he needs to spend in order to win the jackpot and tell how to play.

一名玩家来到一家赌场,发现了一台老虎机,其结果完全取决于玩家的操作方式。规则如下:

屏幕上初始显示一个正整数 aa。玩家每次可投入一枚硬币,然后对任意两个相邻的数字分别执行“加 11”或“减 11”操作(即:对某一对相邻数字,一个加 11,另一个减 11)。执行该操作后,所有数字必须仍为 00 至 99 之间的整数,且最高位数字不能为 00。换言之,禁止对数字 99 执行加 11 操作,禁止对数字 00 执行减 11 操作,也禁止对最高位的 11 执行减 11 操作。一旦屏幕上的数字变为 bb,玩家即赢得头奖。已知 aa 和 bb 的位数相同。

请帮助玩家确定赢得头奖所需的最少硬币数,并说明具体操作方法。

输入格式

The first line contains a single integer nn (2≤n≤1052 \le n \le 10^5) standing for the length of numbers aa and bb.

The next two lines contain numbers aa and bb, each one on a separate line (10n−1≤a,b<10n10^{n-1} \le a, b \lt 10^n).

第一行包含一个整数 nn(2≤n≤1052 \le n \le 10^5),表示数字 aa 和 bb 的位数。

接下来两行每行各包含一个数字,分别为 aa 和 bb(10n−1≤a,b<10n10^{n-1} \le a, b \lt 10^n)。

输出格式

If it is impossible to win the jackpot, print a single integer −1-1.

Otherwise, the first line must contain the minimal possible number cc of coins the player has to spend.

min⁡(c,105)\min(c, 10^5) lines should follow, ii-th of them containing two integers did_i and sis_i (1≤di≤n−11\le d_i\le n - 1, si=±1s_i = \pm 1) denoting that on the ii-th step the player should add sis_i to the did_i-th and (di+1)(d_i + 1)-st digits from the left (e. g. di=1d_i = 1 means that two leading digits change while di=n−1d_i = n - 1 means that there are two trailing digits which change).

Please notice that the answer may be very big and in case c>105c \gt 10^5 you should print only the first 10510^5 moves. Your answer is considered correct if it is possible to finish your printed moves to win the jackpot in the minimal possible number of coins. In particular, if there are multiple ways to do this, you can output any of them.

如果无法赢得头奖,则输出单个整数 −1-1。

否则,第一行必须输出玩家需要花费的最少硬币数 cc。

接下来应输出 min⁡(c,105)\min(c, 10^5) 行,其中第 ii 行包含两个整数 did_i 和 sis_i(满足 1≤di≤n−11\le d_i\le n - 1,且 si=±1s_i = \pm 1),表示在第 ii 步中,玩家应对从左往右数第 did_i 位和第 (di+1)(d_i + 1) 位数字加上 sis_i(例如,di=1d_i = 1 表示改变最前面两位数字,而 di=n−1d_i = n - 1 表示改变最后两位数字)。

请注意,答案可能非常大;当 c>105c > 10^5 时,你只需输出前 10510^5 步操作。只要在你所输出的操作之后,仍能以最少硬币数完成头奖,你的答案即被视为正确。特别地,若存在多种可行方案,你可输出其中任意一种。

输入输出样例

  • 输入#1

    3
    223
    322

    输出#1

    2
    1 1
    2 -1
  • 输入#2

    2
    20
    42

    输出#2

    2
    1 1
    1 1
  • 输入#3

    2
    35
    44

    输出#3

    -1

说明/提示

In the first example, we can make a +1 operation on the two first digits, transforming number 223\textbf{22}3 into 333\textbf{33}3, and then make a -1 operation on the last two digits, transforming 3333\textbf{33} into 3223\textbf{22}.

It's also possible to do these operations in reverse order, which makes another correct answer.

In the last example, one can show that it's impossible to transform 3535 into 4444.

在第一个例子中,我们可以对前两位数字执行一次 +1+1 操作,将数字 223\textbf{22}3 变为 333\textbf{33}3;然后对后两位数字执行一次 −1-1 操作,将 3333\textbf{33} 变为 3223\textbf{22}。

也可以按相反顺序执行这些操作,这同样构成一个正确答案。

在最后一个例子中,可以证明无法将 3535 变为 4444。

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

首页