博客
关于我
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 编译安装 window篇
查看>>
mysql 网络目录_联机目录数据库
查看>>
MySQL 聚簇索引&&二级索引&&辅助索引
查看>>
Mysql 脏页 脏读 脏数据
查看>>
mysql 自增id和UUID做主键性能分析,及最优方案
查看>>
Mysql 自定义函数
查看>>
mysql 行转列 列转行
查看>>
Mysql 表分区
查看>>
mysql 表的操作
查看>>
mysql 视图,视图更新删除
查看>>
MySQL 触发器
查看>>
mysql 让所有IP访问数据库
查看>>
mysql 记录的增删改查
查看>>
MySQL 设置数据库的隔离级别
查看>>
MySQL 证明为什么用limit时,offset很大会影响性能
查看>>
Mysql 语句操作索引SQL语句
查看>>
MySQL 误操作后数据恢复(update,delete忘加where条件)
查看>>
MySQL 调优/优化的 101 个建议!
查看>>
mysql 转义字符用法_MySql 转义字符的使用说明
查看>>
mysql 输入密码秒退
查看>>