Educational Codeforces Round 101 (Rated for Div. 2) E - A Bit Similar
题目传送门
很巧妙的一道题。对于一个 \(n\)位的 \(01\)字符串,一共有 \(2^n\)种不同字符排列,对于任意一个固定排列,在 \(2^n\)种排列中只有一种排列与该固定排列处处不等,而题干中的串长不超过 \(1e6\),小于 \(2^{20}\),也就是说所有长度为 \(20\)的子串不超过 \(1e6\)个,那我们只用让答案串的后 \(20\)位取一个与所有长度为 \(20\)的子串都“相交”的排列,前面都取 \(0\),这样字典序最小。
记录下每个长度为 \(20\)的子串它的排斥串,然后枚举 \([1,1<<20)\)找到最小的非排斥串作为答案串后 \(20\)位。注意只有遇见超过 \(k-20\)个连续 \(1\)时才记录排斥串,然后可能 \(k\)小于 \(20\)所以要取 \(min(k,20)\)。
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 1e6 + 5;
int T, n, k;
char s[N];
bool vis[N];
void solve(){
scanf("%d%d%s", &n, &k, s + 1);
int kk = min(k, 20);
vector<bool> rej(1 << kk, 0);
for(int i = 1, num = 0; i <= n - kk + 1; ++i){
if(num >= k - kk){
int sta = 0;
for(int t = 0; t < kk; ++t){
sta = sta * 2 + (s[i + t] != '1');
}
rej[sta] = 1;
}
num = (s[i] == '1' ? num + 1 : 0);
}
for(int i = 0; i < (1 << kk); ++i){
if(!rej[i]){
puts("YES");
for(int t = 1; t <= k - kk; ++t) putchar('0');
for(int t = kk - 1; ~t; --t) putchar((i & (1 << t)) ? '1' : '0');
puts("");
return ;
}
}
puts("NO");
}
int main(){
scanf("%d", &T);
while(T--) solve();
return 0;
}
Educational Codeforces Round 101 (Rated for Div. 2) E - A Bit Similar的更多相关文章
- Educational Codeforces Round 101 (Rated for Div. 2)
A. Regular Bracket Sequence 题意:题目中给(和)还有?,其中?可以转换成为()中的任何一个,并且所给样例中只出现一次(),问能不能括号匹配 思路:直接看第一个和最后一个能不 ...
- Educational Codeforces Round 76 (Rated for Div. 2)F - Make Them Similar
题意: 给你n个数字(<230),求出一个数字使得所有数字^这个数字之后,二进制状态下的1的个数相同. 解析: 因为最大数字二进制数有30位,所以分为前15位和后15位,分别枚举0-1<& ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 39 (Rated for Div. 2) G
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...
随机推荐
- GIT保存记录原理之commit对象
GIT 中提交对象非常的重要,我们通过它记录代码提交过程.进行文件保存.回退等操作,那么它是怎样帮助我们记录这些信息的呢?其实就是都保存在项目根目录的 .git 文件夹中. 新建空项目 ```gitD ...
- 论文解读(TAT)《 Transferable Adversarial Training: A General Approach to Adapting Deep Classifiers》
Note:[ wechat:Y466551 | 可加勿骚扰,付费咨询 ] 论文信息 论文标题:Transferable Adversarial Training: A General Approach ...
- 震惊!强大的接口自动化测试框架2.0,unittest与pytest无缝穿插对接,可以像postman一样编写代码
theme: fancy highlight: arta 项目介绍 接口自动化测试项目2.0 软件架构 本框架主要是基于 Python + unittest + ddt + HTMLTestRunne ...
- 历时数月钻研推流/对比各种流媒体服务程序/PK总结
1 前言 大量测试下来,网页显示视频流实时性从高到低依次是 webrtc > ws-flv > flv > hls.播放器打开rtsp/rtmp视频流实时性由具体的播放器控制,比如缓 ...
- C#利用Refit实现JWT自动续期
前言 笔者之前开发过一套C/S架构的桌面应用,采用了JWT作为用户的登录认证和授权.遇到的唯一问题就是JWT过期了该怎么办?设想当一个用户正在进行业务操作,突然因为Token过期失效,莫名其妙地跳转到 ...
- 使用 PDF一机一码加密大师,加密打包PDF文件(一机一码,绑定机器,无需额外安装阅读器)
PDF一机一码加密大师, 可以加密任意PDF文档,添加一机一码授权, 静态密码等, 可以禁止用户复制,打印PDF文档中的内容,并且加密生成的PDF在其他用户电脑上无需安装第三方阅读器即可直接阅读. 下 ...
- Springboot优雅参数校验,统一响应,异常处理
1.统一响应 (1)统一状态码 首先定义一个状态码接口,所有状态码都需要实现它 public interface StatusCode { public int getCode(); public S ...
- 【Python爬虫】使用代理ip进行网站爬取
使用代理IP进行网站爬取可以有效地隐藏你的真实IP地址,让网站难以追踪你的访问行为.本文将介绍Python如何使用代理IP进行网站爬取的实现,包括代理IP的获取.代理IP的验证.以及如何把代理IP应用 ...
- 6.swagger完善:界面显示注释+多版本控制
周末,写点简单的水一下. 新版本的vs创建项目的时候可以选择自带一个swagger.然而这只是基本的swagger功能. 几个接口无所谓啦,随着接口越来越多,就这么丢给你,一时间也会懵逼,所以这篇文章 ...
- 【RocketMQ】Dledger模式下的日志复制
RocketMQ在开启Dledger时,使用DLedgerCommitLog,其他情况使用的是CommitLog来管理消息的存储.在Dledger模式下,消息写入时Leader节点还需要将消息转发给F ...