题目链接:http://codeforces.com/contest/1204/problem/D1

D1. Kirk and a Binary String (easy version)
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.

Kirk has a binary string ss (a string which consists of zeroes and ones) of length nn and he is asking you to find a binary string tt of the same length which satisfies the following conditions:

  • For any ll and rr (1≤l≤r≤n1≤l≤r≤n) the length of the longest non-decreasing subsequence of the substring slsl+1…srslsl+1…sr is equal to the length of the longest non-decreasing subsequence of the substring tltl+1…trtltl+1…tr;
  • The number of zeroes in tt is the maximum possible.

A non-decreasing subsequence of a string pp is a sequence of indices i1,i2,…,iki1,i2,…,ik such that i1<i2<…<iki1<i2<…<ik and pi1≤pi2≤…≤pikpi1≤pi2≤…≤pik. The length of the subsequence is kk.

If there are multiple substrings which satisfy the conditions, output any.

Input

The first line contains a binary string of length not more than 20002000.

Output

Output a binary string which satisfied the above conditions. If there are many such strings, output any of them.

Examples
input

Copy

110

output

Copy

010

input

Copy

010

output

Copy

010

input

Copy

0001111

output

Copy

0000000

input

Copy

0111001100111011101000

output

Copy

0011001100001011101000

Note

In the first example:

  • For the substrings of the length 11 the length of the longest non-decreasing subsequnce is 11;
  • For l=1,r=2l=1,r=2 the longest non-decreasing subsequnce of the substring s1s2s1s2 is 1111 and the longest non-decreasing subsequnce of the substring t1t2t1t2 is 0101;
  • For l=1,r=3l=1,r=3 the longest non-decreasing subsequnce of the substring s1s3s1s3 is 1111 and the longest non-decreasing subsequnce of the substring t1t3t1t3 is 0000;
  • For l=2,r=3l=2,r=3 the longest non-decreasing subsequnce of the substring s2s3s2s3 is 11 and the longest non-decreasing subsequnce of the substring t2t3t2t3 is 11;

The second example is similar to the first one.

题目大意:

给出一个 串 S ,求一个串 T  要求,等长所有区间的 LIS(最长上升子序列) 相等,0 的个数尽可能多

题解:

从后向前,保证后面的解都是合法的情况下
如果当前位置的数字是 0
那么,他一定是后面以他为起点的区间的 LIS LISLIS 的一部分,这就要求 T TT 的对应位置必须为 0, 否则 LIS LISLIS 长度必然减少

如果当前位置的数字为 1
考虑,以他为起点的所有区间
对于那些 LIS LISLIS 包含它的区间,就是说 LIS LISLIS 的首项为 1 的区间,他变为0,对这些区间的 LIS LISLIS 没有影响(他们的 LIS LISLIS 长度为 1 的个数)
对于那些 LIS LISLIS 不包含他的区间,就是说 LIS LISLIS 的首项为 0 的区间,他变为0,对这些区间的 LIS LISLIS 会改变

换句话说,若想将 1 变为 0 ,必须保证后面所有的区间的 LIS LISLIS 长度必须和 1 的个数相等!!!

所以,从后向前统计 0 和 1 的数量,当 1 的个数大于等于 0 的个数时,才可以修改

代码:判断后面是否所有区间的1的个数大于0的个数竟然可以O(1)难以想象,一直以为要一遍for才行的

#include<iostream>
#include<cstring>
using namespace std;
int main()
{string s;cin>>s;int len=s.size();int sum=0;for(int i=len-1;i>=0;i--){if(s[i]=='0') sum++;else if(sum) sum--;else s[i]='0';}cout<<s<<endl;return 0;
}

转载于:https://www.cnblogs.com/caijiaming/p/11388982.html

D1. Kirk and a Binary String (easy version)相关推荐

  1. 【CF1204D】Kirk and a Binary String【结论题】【LIS】

    传送门 题意:给一个01串SSS,求一个等长的01串TTT SSS和TTT所有对应位置的子串最长不下降子序列长度(以下简称LIS\text{LIS}LIS)相同 TTT中0的数量尽量多 ∣S∣≤100 ...

  2. CodeForces Round #730 D1. RPD and Rap Sheet (Easy Version)题解

    Codeforces Round #730 (Div. 2) 题意: t组数据,每组给一个n和k,(easy version里面k=2) 每一次系统会输入一个初始的密码(初始密码是一个在[0,n−1] ...

  3. CodeForces - 1543D1 RPD and Rap Sheet (Easy Version)(异或+交互)

    题目链接:点击查看 题目大意:交互题猜密码,设原密码为 xxx,猜的密码为 yyy,如果没猜到,密码会自适应变成 zzz,满足 x⊕z=yx \oplus z=yx⊕z=y ,最多猜 nnn 次 题目 ...

  4. Tokitsukaze and Good 01-String (easy version)

    Tokitsukaze and Good 01-String (easy version) - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 题目描述 This is the easy ...

  5. Codeforces Round #579 (Div. 3) F1. Complete the Projects (easy version) 排序 + 贪心

    传送门 文章目录 题意: 思路: 题意: 思路: 比较直观的想法就是对于bi≥0b_i\ge0bi​≥0的项目,我们将aia_iai​从小到大排序,让后依次加bib_ibi​,如果有取不到的,显然就无 ...

  6. 1282B1. K for the Price of One (Easy Version)

    B1. K for the Price of One (Easy Version):题目 两种情况,前面取一或者前面不取 #include <bits/stdc++.h> using na ...

  7. 1420C1. Pokémon Army (easy version)

    C1. Pokémon Army (easy version):题目 题意:选择其中一部分,按照+-依此计算,求总和 思路:找到局部最大值,然后减去局部最小值,依此找. #include <bi ...

  8. 智乃的数字积木(easy version)<每日一题>

    题目: 题目链接: 登录-专业IT笔试面试备考平台_牛客网 题目思路(easy version): 封装一个能够在相同颜色交换位置 并将字符串转换成数字 的自定义函数 再每次改变颜色后 只需修改颜色值 ...

  9. LeetCode刷题记录4——67. Add Binary(easy)

    LeetCode刷题记录4--67. Add Binary(easy) 目录 LeetCode刷题记录4--67. Add Binary(easy) 题目 语言 思路 后记 题目 今天这题是与字符串相 ...

最新文章

  1. 列出本机正在监控的端口
  2. 语音识别1: 音频信号采集、并存入 wav文件
  3. 2020年_Jsp Jstl 学习笔记
  4. 前端学习(1355) 子模板
  5. 腾讯四季度数实经济收入首超游戏达479.58亿元
  6. MYSQL 中 SQL 常用操作
  7. php原生数据库分页
  8. mysql 页 存储,MySQL InnoDB Engine--数据页存储和UPDATE操作
  9. codeforces 580C Kefa and Park(DFS)
  10. keyup常用事件_KeyUp 事件
  11. 关于Decorator模式
  12. noip2013解题报告
  13. 【控件】mars3d控件的设置
  14. cad单位_CAD标注样式如何转换公制和英制
  15. 已解决:不小心卸载pip后(重新安装pip的两种方式)
  16. Movist Pro for Mac 2.2.16 — 播放器
  17. System.BadImageFormatException:试图加载格式不正确的程序。(异常来自 HRESULT:0x8007000B)
  18. 干货 | DDD实战:基于洋葱模型的分层代码架构设计
  19. 常规计算机 符号键是,有谁知道电脑键盘上的标示符号都代表什么意思
  20. 项目之动态图片的制作

热门文章

  1. ruby学习笔记(3)--语法层面的先见之明
  2. Visual SourceSafe使用流程指南
  3. C#无法生成解决方案,System.InvalidOperationException: 此实现不是 Windows 平台 FIPS 验证的加密算法的一部分。
  4. no plugin found for prefix ‘tomcat 7‘ in the current project and in the plugin groups的解决方法
  5. 【报告分享】2019全球数字经济新图景.pdf
  6. 10条设计推荐系统的经验和教训
  7. python摄像头跟随人脸_opencv-python 学习笔记2:实现目光跟随(又叫人脸跟随)
  8. sql找出2000-3000年中的闰年。_跟飞哥学编程:SQL入门-4-查询和条件
  9. oracle and和or的执行顺序,Oraclewhere语句中and,or,not的执行顺序
  10. 召回离线评估指标(一)