A12657 | Long Number
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a long decimal number $a$ consisting of $n$ digits from $1$ to $9$ . You also have a function $f$ that maps every digit from $1$ to $9$ to some (possibly the same) digit from $1$ to $9$ .
You can perform the following operation no more than once: choose a non-empty contiguous subsegment of digits in $a$ , and replace each digit $x$ from this segment with $f(x)$ . For example, if $a = 1337$ , $f(1) = 1$ , $f(3) = 5$ , $f(7) = 3$ , and you choose the segment consisting of three rightmost digits, you get $1553$ as the result.
What is the maximum possible number you can obtain applying this operation no more than once?
You can perform the following operation no more than once: choose a non-empty contiguous subsegment of digits in $a$ , and replace each digit $x$ from this segment with $f(x)$ . For example, if $a = 1337$ , $f(1) = 1$ , $f(3) = 5$ , $f(7) = 3$ , and you choose the segment consisting of three rightmost digits, you get $1553$ as the result.
What is the maximum possible number you can obtain applying this operation no more than once?
输入格式
The first line contains one integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the number of digits in $a$ .
The second line contains a string of $n$ characters, denoting the number $a$ . Each character is a decimal digit from $1$ to $9$ .
The third line contains exactly $9$ integers $f(1)$ , $f(2)$ , ..., $f(9)$ ( $1 \le f(i) \le 9$ ).
The second line contains a string of $n$ characters, denoting the number $a$ . Each character is a decimal digit from $1$ to $9$ .
The third line contains exactly $9$ integers $f(1)$ , $f(2)$ , ..., $f(9)$ ( $1 \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
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted