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. scala简单的文件操作

    1.scala写入文件操作 package com.test import java.io.File import java.io.PrintWriter /** * scala文件写入 */ obj ...

  2. CC2541的任务与事件,以及红外捕捉.

    因为红外遥控要占用的系统中断时间可能超过了80ms, 极有可能导致蓝牙断线, 特别是连续两次按键, 100%断线. 后来根据蓝牙技术群里的哥们提示, 觉得不能在一个中断中delay得太久, 只能用任务 ...

  3. Android 常用工具类之DeviceInfoUtil

    public class DeviceInfoUtil { private static WifiManager wifiManager = null; // wifi是否已连接 public sta ...

  4. eclipse 利用已有c++代码建工程,并编译执行

    如果你想建一个带Makefile的c++ 工程 1. 新建一个C++空工程,工程类型是makefile project,选择Linux GCC: 2. 将源码连同makefile文件一同作为一个文件系 ...

  5. rsync 只同步指定类型的文件

    需求: 同步某个目录下所有的图片(*.jpg),该目录下有很多其他的文件,但只想同步*.jpg的文件. rsync 有一个--exclude 可以排除指定文件,还有个--include选项的作用正好和 ...

  6. cut DEMO

    分割后得到列: cat /etc/passwd|head -n 5 | cut -d : -f 1,6

  7. ojdbc5.jar

    ojdbc5.jar:http://files.cnblogs.com/files/xiluhua/ojdbc5.rar

  8. Haproxy安装与配置

    一.Haproxy概念 Haproxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.Haproxy特别适用于那些负载特大的web站点,这 ...

  9. Codeforces 745C:Hongcow Builds A Nation(并查集)

    http://codeforces.com/problemset/problem/744/A 题意:在一个图里面有n个点m条边,还有k个点是受限制的,即不能从一个受限制的点走到另外一个受限制的点(有路 ...

  10. 网络统计学与web前端开发基础技术

    网络统计学与web前端开发基础技术 学习web前端开发基础技术(网页设计)需要了解:HTML.CSS.JavaScript三种语言.下面我们就来了解一下这三门技术在网页设计中的用途: HTML是网页内 ...