博客
关于我
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/

你可能感兴趣的文章
MyEcplise中SpringBoot怎样定制启动banner?
查看>>
MyPython
查看>>
MTD技术介绍
查看>>
MySQL
查看>>
MySQL
查看>>
mysql
查看>>
MTK Android 如何获取系统权限
查看>>
MySQL - 4种基本索引、聚簇索引和非聚索引、索引失效情况、SQL 优化
查看>>
MySQL - ERROR 1406
查看>>
mysql - 视图
查看>>
MySQL - 解读MySQL事务与锁机制
查看>>
MTTR、MTBF、MTTF的大白话理解
查看>>
mt_rand
查看>>
mysql -存储过程
查看>>
mysql /*! 50100 ... */ 条件编译
查看>>
mudbox卸载/完美解决安装失败/如何彻底卸载清除干净mudbox各种残留注册表和文件的方法...
查看>>
mysql 1264_关于mysql 出现 1264 Out of range value for column 错误的解决办法
查看>>
mysql 1593_Linux高可用(HA)之MySQL主从复制中出现1593错误码的低级错误
查看>>
mysql 5.6 修改端口_mysql5.6.24怎么修改端口号
查看>>
MySQL 8.0 恢复孤立文件每表ibd文件
查看>>