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. 067-PHP使用匿名函数

    <?php $func=function ($x,$y){ //匿名函数与变量绑定 return $x+$y; }; echo '5+6='.$func(5,6); //使用匿名函数 echo ...

  2. Java中调试与测试常用方法

    一.断言 1.概述 根据之前的条件来对后续的结果进行预判. 2.在Java中,断言默认是不开启的,需要手动进行开启,只需添加参数-ea(enable assert的意思) 开启步骤: 选中项目路径,鼠 ...

  3. 【pwnable.kr】col

    pwnable从入门到放弃第二题, ssh col@pwnable.kr -p2222 (pw:guest) 同样是登录,然后看到了col.c.col.flag三个文件,读一下col.c #inclu ...

  4. Arduino --structure

    The elements of Arduino (C++) code. Sketch loop() setup() Control Structure break continue do...whil ...

  5. bzoj1415 NOI2005聪聪和可可

    %%%http://hzwer.com/2819.html 先各种暴力搞出来p[x][y](从x到y下一个最近应该到达的位子) 然后就记忆化搜索??(雾) #include<bits/stdc+ ...

  6. 安装kubernetes遇见coredns坑

    安装kubernetes遇见问题 kubectl describe pod coredns -n kube-system, 查看发现coredns readiness 一直unhealthy, 并且一 ...

  7. maven项目中WEB-INF的父目录必须叫webapp吗?

    这个并不是必须的,可以在pom配置文件中修改,如下所示: <webappDirectory>src/main/WebContent</webappDirectory>      ...

  8. 八、CI框架之输出URI路径,相当于GET

    一.controller中的代码如下: 二.我们打开一个路径,输出对应的路径URI的值 http://127.0.0.1/CodeIgniter-3.1.10/index.php/welcome/in ...

  9. sqlserver 存储过程 C#调用 实现从数据库Get数据

    在最近的项目中我想建立一个EFDBfirst的模型但是失败了,生成的edmx中没有实体类和表结构,到处需求解决方案,未果. 问题请见:https://q.cnblogs.com/q/102743/ 后 ...

  10. Swift 3 :基于 AVAudioPlayer 的简单音乐播放器

    2017.05.22 17:46* 字数 1585 阅读 5095评论 0喜欢 8赞赏 2 https://www.jianshu.com/p/4d5c257428a1 学习ios以来差不多接近两个月 ...