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

你可能感兴趣的文章
mysql5.7性能调优my.ini
查看>>
MySQL5.7新增Performance Schema表
查看>>
Mysql5.7深入学习 1.MySQL 5.7 中的新增功能
查看>>
Webpack 之 basic chunk graph
查看>>
Mysql5.7版本单机版my.cnf配置文件
查看>>
mysql5.7的安装和Navicat的安装
查看>>
mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
查看>>
Mysql8 数据库安装及主从配置 | Spring Cloud 2
查看>>
mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
查看>>
MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
查看>>
MYSQL8.0以上忘记root密码
查看>>
Mysql8.0以上重置初始密码的方法
查看>>
mysql8.0新特性-自增变量的持久化
查看>>
Mysql8.0注意url变更写法
查看>>
Mysql8.0的特性
查看>>
MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
查看>>
MySQL8修改密码的方法
查看>>
Mysql8在Centos上安装后忘记root密码如何重新设置
查看>>
Mysql8在Windows上离线安装时忘记root密码
查看>>
MySQL8找不到my.ini配置文件以及报sql_mode=only_full_group_by解决方案
查看>>