博客
关于我
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中cast() 和convert()的用法讲解
查看>>
mysql中datetime与timestamp类型有什么区别
查看>>
MySQL中DQL语言的执行顺序
查看>>
mysql中floor函数的作用是什么?
查看>>
MySQL中group by 与 order by 一起使用排序问题
查看>>
mysql中having的用法
查看>>
MySQL中interactive_timeout和wait_timeout的区别
查看>>
mysql中int、bigint、smallint 和 tinyint的区别、char和varchar的区别详细介绍
查看>>
mysql中json_extract的使用方法
查看>>
mysql中json_extract的使用方法
查看>>
mysql中kill掉所有锁表的进程
查看>>
mysql中like % %模糊查询
查看>>
MySql中mvcc学习记录
查看>>
mysql中null和空字符串的区别与问题!
查看>>