E. Restoring Increasing Sequence
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Peter wrote on the board a strictly increasing sequence of positive integers a1, a2, ..., an. Then Vasil replaced some digits in the numbers of this sequence by question marks. Thus, each question mark corresponds to exactly one lost digit.

Restore the the original sequence knowing digits remaining on the board.

Input

The first line of the input contains integer n (1 ≤ n ≤ 105) — the length of the sequence. Next n lines contain one element of the sequence each. Each element consists only of digits and question marks. No element starts from digit 0. Each element has length from 1 to 8 characters, inclusive.

Output

If the answer exists, print in the first line "YES" (without the quotes). Next n lines must contain the sequence of positive integers — a possible variant of Peter's sequence. The found sequence must be strictly increasing, it must be transformed from the given one by replacing each question mark by a single digit. All numbers on the resulting sequence must be written without leading zeroes. If there are multiple solutions, print any of them.

If there is no answer, print a single line "NO" (without the quotes).

Examples
Input
3
?
18
1?
Output
YES
1
18
19
Input
2
??
?
Output
NO
Input
5
12224
12??5
12226
?0000
?00000
Output
YES
12224
12225
12226
20000
100000
题意:给你n个数,但是有些数字不知道,需要你填写,使得最后的序列为一个严格递增的序列
思路:一个二分,但是这个二分很特别,刚刚开始想,二分这个数,使得最小满足大于上一个数,
   也满足给你那个数的原来的那些数,但是发现不好写,转化一下,把原来给的数剔除掉,
   把那些问号拼凑成一个数,二分问号的这个数,然后分开填进去看是否满足;
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+,MOD=1e9+;
char a[N][],b[];
int c[];
int ans[N];
int check(int x,int pos)
{
int len=strlen(a[pos]);
for(int i=;i<len;i++)
b[i]=a[pos][i];
for(int i=len-;i>=;i--)
{
if(b[i]=='?')
{
b[i]=x%+'';
x/=;
}
}
int ans=;
for(int i=;i<len;i++)
ans=ans*+b[i]-'';
return ans;
}
int lower(int x,int pos)
{
int flag=;
int st=;
int en=;
int ans=-;
for(int i=;i<strlen(a[pos]);i++)
{
if(a[pos][i]=='?')
flag++,en*=;;
}
if(a[pos][]=='?')
st=en/;
en--;
while(st<=en)
{
int mid=(st+en)>>;
//cout<<mid<<" "<<check(x,pos)<<" "<<x<<" "<<endl;
if(check(mid,pos)>x)
{
ans=mid;
en=mid-;
}
else
st=mid+;
}
if(ans==-)
return -;
for(int i=strlen(a[pos])-;i>=;i--)
{
if(a[pos][i]=='?')
{
a[pos][i]=ans%+'';
ans/=;
}
}
int sum=;
for(int i=;i<strlen(a[pos]);i++)
sum=sum*+a[pos][i]-'';
return sum;
}
int main()
{ int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%s",&a[i]);
int pre=;
for(int i=;i<=n;i++)
{
ans[i]=lower(pre,i);
if(ans[i]==-)
return puts("NO\n");
pre=ans[i];
}
printf("YES\n");
for(int i=;i<=n;i++)
{
printf("%d\n",ans[i]);
}
return ;
}

Codeforces Round #279 (Div. 2) E. Restoring Increasing Sequence 二分的更多相关文章

  1. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  2. Codeforces Round #365 (Div. 2) C - Chris and Road 二分找切点

    // Codeforces Round #365 (Div. 2) // C - Chris and Road 二分找切点 // 题意:给你一个凸边行,凸边行有个初始的速度往左走,人有最大速度,可以停 ...

  3. Codeforces Round #279 (Div. 2) 题解集合

    终于有场正常时间的比赛了...毛子换冬令时还正是好啊233 做了ABCD,E WA了3次最后没搞定,F不会= = 那就来说说做的题目吧= = A. Team Olympiad 水题嘛= = 就是个贪心 ...

  4. Codeforces Round #353 (Div. 2) B. Restoring Painting 水题

    B. Restoring Painting 题目连接: http://www.codeforces.com/contest/675/problem/B Description Vasya works ...

  5. 【Codeforces Round#279 Div.2】B. Queue

    这题看别人的.就是那么诚实.http://www.cnblogs.com/zhyfzy/p/4117481.html B. Queue During the lunch break all n Ber ...

  6. Codeforces Round #279 (Div. 2) B. Queue

    B. Queue time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  7. Codeforces Round #279 (Div. 2) vector

    A. Team Olympiad time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

  8. Codeforces Round #279 (Div. 2) C. Hacking Cypher 前缀+后缀

    C. Hacking Cypher time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  9. CodeForces Round #279 (Div.2)

    A: 题意: 有三个项目和n个学生,每个学生都擅长其中一个项目,现在要组成三个人的队伍,其中每个人恰好擅长其中一门,问能组成多少支队伍. 分析: 最多能组成的队伍的个数就是擅长项目里的最少学生. #i ...

随机推荐

  1. PS4 的下载速度问题

    折腾了好久了 AC68u路由自启动修改 hosts 问题,打算FQ另外改善 ps4 下载速度太慢问题. 后来看到几个dns, 直接修改后就速度超快,也不用在路由中添加了, 直接在 ps4 中网络设置中 ...

  2. uboot启动参数

    bootcmd=nand read.jffs2 0x30007FC0 kernel; bootm 0x30007FC0bootdelay=2baudrate=115200ethaddr=08:00:3 ...

  3. laravel队列

    三种情况: queue:work 默认只执行一次队列请求, 当请求执行完成后就终止; queue:listen 监听队列请求, 只要运行着, 就能一直接受请求, 除非手动终止; queue:work ...

  4. eclipse折叠快捷键

    之前按代码折叠快捷键的时候发现时而灵时而不灵,今天突然发现了问题所在: 按ctrl+/(小键盘)使代码左边出现折叠标志 然后再按ctrl+shift+/(折叠)   , ctrl+shift+*(展开 ...

  5. mysql+keepalived主从切换脚本 转

    Keepalived MySQL故障自动切换脚本   MySQL架构为master-slave(主从),master故障自动切换到slave上.当然也可以设置为双master,但这里有个弊端:就是当主 ...

  6. flex datagrid 换行

    <mx:DataGrid id="myGrid" width="100%" height="90%" headerStyleName= ...

  7. java对象的序列化与反序列化使用

    1.Java序列化与反序列化  Java序列化是指把Java对象转换为字节序列的过程:而Java反序列化是指把字节序列恢复为Java对象的过程. 2.为什么需要序列化与反序列化 我们知道,当两个进程进 ...

  8. 打开开源项目总得.md文件

    google了一些: 78 Tools for Writing and Previewing Markdown  http://mashable.com/2013/06/24/markdown-too ...

  9. log4j里面的info,debug,error级别有什么区别

    一共分为五个级别:DEBUG.INFO.WARN.ERROR和FATAL.这五个级别是有顺序的,DEBUG < INFO < WARN < ERROR < FATAL,明白这一 ...

  10. 21、JavaScript加强

      1)回顾JS中核心内容 2)了解WEB1.0和WEB2.0时代的技术与特点 3)理解AJAX的产生背景.工作原理与特点 4)掌握AJAX常用API及应用   声明:服务端我们使用Servlet技术 ...