B. Long Number
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a long decimal number aa consisting of nn digits from 11 to 99. You also have a function ff that maps every digit from 11 to 99 to some (possibly the same) digit from 11 to 99.

You can perform the following operation no more than once: choose a non-empty contiguous subsegment of digits in aa, and replace each digit xx from this segment with f(x)f(x). For example, if a=1337a=1337, f(1)=1f(1)=1, f(3)=5f(3)=5, f(7)=3f(7)=3, and you choose the segment consisting of three rightmost digits, you get 15531553 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 nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of digits in aa.

The second line contains a string of nn characters, denoting the number aa. Each character is a decimal digit from 11 to 99.

The third line contains exactly 99 integers f(1)f(1), f(2)f(2), ..., f(9)f(9) (1≤f(i)≤91≤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
题意:在字符串中任意选择一个子串,将该子串中的数字按照题目的替换规则进行替换(无论替换之后,新数字比旧数字大还是小,只要在字串范围之内都要替换),找出替换后的最大数字;
这个数字替换是在字符串的某一段区间的,在这段区间中所有的就数字都要被新数字替换,所以我们最先找到的子串(其中替换后的新数字都比就数字大,遇到新数字比旧数字小,就停止),就可以的得到最大数字
错因:一开始以为替换区间是整个字符串,然后按照新数字比就数字大就替换,新数字比就数字小就不替换,然后 WA6了。
 #include<stdio.h>
#include<string>
#include<string.h>
using namespace std; int n,num[],judge[];
char m[];
int main(){
scanf("%d",&n);getchar();
for(int i = ; i <= n ; i++){
scanf("%c",&m[i]);
}
for(int i = ; i <= n ; i++){
num[i] = m[i] - ;
}
int cnt = n;
for(int i = ; i <= ; i++){
scanf("%d",&judge[i]);
}
int ret = ;
for(int i = ; i <= n ; i++){
if(ret == && judge[num[i]] < num[i]){
ret++;
}
if(judge[num[i]] > num[i] && ret == ){
num[i] = judge[num[i]];
ret = ;
}else if(judge[num[i]] > num[i] && ret == ){
num[i] = judge[num[i]];
} printf("%d",num[i]);
}
printf("\n");
return ;
}

AC代码

一个从很久以前就开始做的梦。

Codeforces Round #555 (Div. 3) B. Long Number 【仔细读题】的更多相关文章

  1. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  2. Codeforces Round #298 (Div. 2) A、B、C题

    题目链接:Codeforces Round #298 (Div. 2) A. Exam An exam for n students will take place in a long and nar ...

  3. Codeforces Round #281 (Div. 2) B. Vasya and Wrestling 水题

    B. Vasya and Wrestling 题目连接: http://codeforces.com/contest/493/problem/B Description Vasya has becom ...

  4. 老年OIer的Python实践记—— Codeforces Round #555 (Div. 3) solution

    对没错下面的代码全部是python 3(除了E的那个multiset) 题目链接:https://codeforces.com/contest/1157 A. Reachable Numbers 按位 ...

  5. Codeforces Round #427 (Div. 2) B. The number on the board

    引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...

  6. Codeforces Round #585 (Div. 2) B. The Number of Products(DP)

    链接: https://codeforces.com/contest/1215/problem/B 题意: You are given a sequence a1,a2,-,an consisting ...

  7. CodeForces Round #555 Div.3

    A. Reachable Numbers 代码: #include <bits/stdc++.h> using namespace std; ; int N; set<int> ...

  8. Codeforces Round #555 (Div. 3) AB

    A:    http://codeforces.com/contest/1157/problem/A 题意:每次加到10的整数倍之后,去掉后面的0,问最多有多少种可能. #include <io ...

  9. Codeforces Round #555 (Div. 3)[1157]题解

    不得不说这场div3是真的出的好,算得上是从我开始打开始最有趣的一场div3.因为自己的号全都蓝了,然后就把不经常打比赛的dreagonm的号借来打这场,然后...比赛结束rank11(帮dreago ...

随机推荐

  1. 153-PHP htmlentities函数

    <?php //定义一个HTML代码字符串 $str=<<<HTM <a href=#><b><i>到一个网址的链接</i>&l ...

  2. Python MySQL 创建表

    章节 Python MySQL 入门 Python MySQL 创建数据库 Python MySQL 创建表 Python MySQL 插入表 Python MySQL Select Python M ...

  3. jedis哨兵模式的redis组(集群),连接池实现。(客户端分片)

    java 连接redis 我们都使用的 是jedis  ,对于redis这种频繁请求的场景我们一般需要对其池化避免重复创建,即创建一个连接池 ,打开jedis的 jar包我们发现,jedis对池已经有 ...

  4. vue左侧菜单的实现

    后端实现 django视图def menu(request): menu_list = models.Menu.objects.all().values('id', 'menu_name', 'par ...

  5. 快速搭建单机版Spring Cloud EurekaServer

    原文链接:http://www.yiidian.com/springcloud/build-eureka-single.html 本文介绍搭建单机版的Eureka Server服务 1 创建项目,导入 ...

  6. pytorch随笔

    pytorch中transform函数 一般用Compose把多个步骤整合到一起: 比如说 transforms.Compose([ transforms.CenterCrop(10), transf ...

  7. POJ 1422 DAG最小路径覆盖

    求无向图中能覆盖每个点的最小覆盖数 单独的点也算一条路径 这个还是可以扯到最大匹配数来,原因跟上面的最大独立集一样,如果某个二分图(注意不是DAG上的)的边是最大匹配边,那说明只要取两个端点只要一条边 ...

  8. iOS内存管理布局及管理方案-理论篇

    苹果设备备受欢迎的背后离不开iOS优秀的内存管理机制,那iOS的内存布局及管理方案是怎样的呢?我们一起研究下. 内存管理分为五大块 栈区(stack):线性结构,内存连续,系统自己管理内存,程序运行记 ...

  9. idea xml文件去掉背景黄色

    编写dao中的sql时,xml文件中背景一大片黄色,看着不舒服,如何去掉了? 1. File -> Settings... 2. 去消以下两项勾选    (Inspections    -- 如 ...

  10. [GXYCTF2019]BabySQli

    0x00 知识点 emmm这道题目就是脑洞得大,能猜后端源码 0x01 解题 查看源码: base32,base64解码得到 select * from user where username = ' ...