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. ThinkPHP 3.2.3的 R 方法

    R方法是可以调用其他的Controller中的方法, 例如 我想在Mit/DebugController.class.php中调用Foo/DoController.class.php中的share方法 ...

  2. remote desktop connect btw Mac, Windows, Linux(Ubuntu) Mac,Windows,Linux之间的远程桌面连接

    目录 I. 预备 II. Mac连接Windows III. Windows连接Mac IV. Windows连接Ubuntu V. Mac连接Ubuntu VI. Ubuntu连接Mac VII, ...

  3. 虚拟机 本地 本机 双启动 运行 vhd local Dual Boot

    在使用虚拟机的过程中, 可能会遇到虚拟机的运行要求过高, 电脑力不从心的情况. 为了让虚拟机使用更多电脑资源, 可以让虚拟机以本地双系统的方式,访问本地计算机资源. 打开磁盘管理,在磁盘上右键,选择 ...

  4. linux man

    man能够为除命令之外的配置文件.系统调用.库调用等都能提供帮助手册,他们分别位于不同的章节中: 1.用户命令 2.系统调用 3.库调用 4.设备文件 5.配置文件 6.游戏 7.杂项 8.管理命令

  5. c# 反射列子

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  6. mysql一些常用命令总结

    mysql时间戳转日期格式SELECT FROM_UNIXTIME(add_time,'%Y-%m-%d %H:%i:%s') FROM `wh5_username` where id=23; 按in ...

  7. 转载-python学习笔记之常用模块用法分析

    内置模块(不用import就可以直接使用)   常用内置函数   help(obj) 在线帮助, obj可是任何类型 callable(obj) 查看一个obj是不是可以像函数一样调用 repr(ob ...

  8. [Django_1_1]第一个app

    Django 第一个app 本篇负责介绍添加第一个Django app. 本篇文章的上一篇为:Django 初次见面 关于App和Project 简单的来说,一个项目(Project)可以由很多个应用 ...

  9. 探索Win32系统之窗口类(转载)

    Window Classes in Win32 摘要 本文主要介绍win32系统里窗口类的运做和使用机制,探索一些细节问题,使win32窗口类的信息更加明朗化. 在本文中,"类", ...

  10. java实现按拼音排序名称

    private static String[] nameArray = {"张三","李四","王二","付火"}; @ ...