CF1157B.Long Number

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a long decimal number aa consisting of nn digits from 11 to 99. You also have a function ff that maps every digit from 11 to 99 to some (possibly the same) digit from 11 to 99.

You can perform the following operation no more than once: choose a non-empty contiguous subsegment of digits in aa, and replace each digit xx from this segment with f(x)f(x). For example, if a=1337a = 1337, f(1)=1f(1) = 1, f(3)=5f(3) = 5, f(7)=3f(7) = 3, and you choose the segment consisting of three rightmost digits, you get 15531553 as the result.

What is the maximum possible number you can obtain applying this operation no more than once?

给你一个由 nn 个数字(每个数字均为 11 到 99 之间的整数)组成的长十进制数 aa。你还拥有一个函数 ff,它将每个 11 到 99 的数字映射为某个(可能相同)的 11 到 99 的数字。

你最多可以执行以下操作一次:选择 aa 中一个非空的连续子段,并将该子段中的每个数字 xx 替换为 f(x)f(x)。例如,若 a=1337a = 1337,f(1)=1f(1) = 1,f(3)=5f(3) = 5,f(7)=3f(7) = 3,且你选择最右侧的三个数字构成的子段,则结果为 15531553。

在最多执行一次该操作的前提下,你能得到的最大可能的数是多少?

输入格式

The first line contains one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of digits in aa.

The second line contains a string of nn characters, denoting the number aa. Each character is a decimal digit from 11 to 99.

The third line contains exactly 99 integers f(1)f(1), f(2)f(2), ..., f(9)f(9) (1≤f(i)≤91 \le f(i) \le 9).

第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示数字 aa 的位数。

第二行包含一个长度为 nn 的字符串,表示数字 aa。每个字符均为从 11 到 99 的十进制数字。

第三行恰好包含 99 个整数 f(1)f(1)、f(2)f(2)、…、f(9)f(9)(1≤f(i)≤91 \le f(i) \le 9)。

输出格式

Print the maximum number you can get after applying the operation described in the statement no more than once.

输出在至多执行一次题目描述中的操作后能得到的最大数字。

输入输出样例

  • 输入#1

    4
    1337
    1 2 5 4 6 6 3 1 9

    输出#1

    1557
  • 输入#2

    5
    11111
    9 8 7 6 5 4 3 2 1

    输出#2

    99999
  • 输入#3

    2
    33
    1 1 1 1 1 1 1 1 1

    输出#3

    33

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

首页