博客
关于我
Promblem—— B. Long Number ——Codefordes
阅读量:289 次
发布时间:2019-03-01

本文共 1862 字,大约阅读时间需要 6 分钟。

B. Long Number

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
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?

Input

The first line contains one integer n (1≤n≤2⋅105) — 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≤f(i)≤9).

Output

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

Examples

input

4

1337
1 2 5 4 6 6 3 1 9

output

1557

input

5

11111
9 8 7 6 5 4 3 2 1

output

99999

input

2

33
1 1 1 1 1 1 1 1 1

output

33

思路:

原本以为只是一道映射题,结果发现是要把原本的数变大,并且映射一旦使用那么一旦下一个数不能大于映射的数,那么映射暂停,输出结果。

代码:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long#define dd double#define mes(x,y) memset(x,y,sizeof(y))using namespace std;int main(){ ll n;string s; while(cin>>n>>s){ int a[15]; for(int i=1;i<=9;i++)cin>>a[i]; for(ll i=0;i
s[i]){ //找到开始映射的位置,开始暴力 for(int j=i;j
=s[j]){ s[j]=a[s[j]-'0']+'0'; }//在映射中可以有相同的存在,最外面的判断不加相等是因为那个位置没有改变的必要,然而里面加等于是为了映射次数更多,是这个数变的更大 else{ break; } } break; } } cout<
<

转载地址:http://grvo.baihongyu.com/

你可能感兴趣的文章
Mysql 学习总结(87)—— Mysql 执行计划(Explain)再总结
查看>>
Mysql 学习总结(88)—— Mysql 官方为什么不推荐用雪花 id 和 uuid 做 MySQL 主键
查看>>
Mysql 学习总结(89)—— Mysql 库表容量统计
查看>>
mysql 实现主从复制/主从同步
查看>>
mysql 审核_审核MySQL数据库上的登录
查看>>
mysql 导入 sql 文件时 ERROR 1046 (3D000) no database selected 错误的解决
查看>>
mysql 导入导出大文件
查看>>
MySQL 导出数据
查看>>
mysql 将null转代为0
查看>>
mysql 常用
查看>>
MySQL 常用列类型
查看>>
mysql 常用命令
查看>>
Mysql 常见ALTER TABLE操作
查看>>
MySQL 常见的 9 种优化方法
查看>>
MySQL 常见的开放性问题
查看>>
Mysql 常见错误
查看>>
mysql 常见问题
查看>>
MYSQL 幻读(Phantom Problem)不可重复读
查看>>
mysql 往字段后面加字符串
查看>>
mysql 快照读 幻读_innodb当前读 与 快照读 and rr级别是否真正避免了幻读
查看>>