当前位置:网站首页>C. Binary String Reconstruction
C. Binary String Reconstruction
2022-08-09 21:55:00 【秦小咩】
C. Binary String Reconstruction
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Consider the following process. You have a binary string (a string where each character is either 0 or 1) ww of length nn and an integer xx. You build a new binary string ss consisting of nn characters. The ii-th character of ss is chosen as follows:
- if the character wi−xwi−x exists and is equal to 1, then sisi is 1 (formally, if i>xi>x and wi−x=wi−x= 1, then si=si= 1);
- if the character wi+xwi+x exists and is equal to 1, then sisi is 1 (formally, if i+x≤ni+x≤n and wi+x=wi+x= 1, then si=si= 1);
- if both of the aforementioned conditions are false, then sisi is 0.
You are given the integer xx and the resulting string ss. Reconstruct the original string ww.
Input
The first line contains one integer tt (1≤t≤10001≤t≤1000) — the number of test cases.
Each test case consists of two lines. The first line contains the resulting string ss (2≤|s|≤1052≤|s|≤105, each character of ss is either 0 or 1). The second line contains one integer xx (1≤x≤|s|−11≤x≤|s|−1).
The total length of all strings ss in the input does not exceed 105105.
Output
For each test case, print the answer on a separate line as follows:
- if no string ww can produce the string ss at the end of the process, print −1−1;
- otherwise, print the binary string ww consisting of |s||s| characters. If there are multiple answers, print any of them.
Example
input
Copy
3 101110 2 01 1 110 1
output
Copy
111011 10 -1
=========================================================================
我们先满足必须是0的位置,然后为了尽可能满足其余1的情况,我们让剩余位置全是1即可,然后在进行无解的判断,条件就按照题目给的写就够了
# include<iostream>
# include<string.h>
using namespace std;
char s[100000+10],t[100000+10];
int main ()
{
int n;
cin>>n;
while(n--)
{
scanf("%s",s+1);
int x;
cin>>x;
for(int i=1;i<=strlen(s+1);i++)
{
t[i]='1';
}
for(int i=1;i<=strlen(s+1);i++)
{
if(s[i]=='0')
{
if(i-x>=1)
t[i-x]='0';
if(i+x<=strlen(s+1))
t[i+x]='0';
}
}
int flag=0;
for(int i=1;i<=strlen(s+1);i++)
{
if(s[i]=='1')
{
if(!((i-x>=1&&t[i-x]=='1')||(i+x<=strlen(s+1)&&t[i+x]=='1')))
{
flag=1;
break;
}
}
else
{
if((i-x>=1&&t[i-x]=='1')||(i+x<=strlen(s+1)&&t[i+x]=='1'))
flag=1;
}
}
if(flag)
{
cout<<"-1"<<endl;
}
else
{
for(int i=1;i<=strlen(s+1);i++)
{
cout<<t[i];
}
cout<<endl;
}
}
return 0;
}
边栏推荐
- Rust 解引用
- 【EF】 更新条目时出错。有关详细信息,请参见内部异常。[通俗易懂]
- CVPR22 Oral | shunt through multi-scale token polymerization from attention, code is open source
- JS–比想象中简单
- 18-GuliMall 压力测试与性能监控
- abstract class or interface
- Five Star Holdings Wang Jianguo: Deepen the track with "plant spirit" and promote growth with "animal spirit"
- Metasploit常用命令、技术功能模块
- JS解混淆-AST还原案例
- JS Deobfuscation - AST Restoration Case
猜你喜欢
18-GuliMall 压力测试与性能监控
Converting angles to radians
Js fifteen interview questions (with answers)
Pagoda measurement - building LightPicture open source map bed system
shell学习
leetcode 刷题日记 计算右侧小于当前元素的个数
Install win virtual machine on VMware
CVPR22 Oral | shunt through multi-scale token polymerization from attention, code is open source
Presto Event Listener开发
肝通宵写了三万字把SQL数据库的所有命令,函数,运算符讲得明明白白讲解,内容实在丰富,建议收藏+三连好评!
随机推荐
TRUNCATE表之后空间未释放
BulkInsert方法实现批量导入
PHP 2D array sorted by a field
In-depth analysis of Apache EventMesh cloud-native distributed event-driven architecture
Five Star Holdings Wang Jianguo: Deepen the track with "plant spirit" and promote growth with "animal spirit"
开发者必备:一文快速熟记【数据库系统】和【软件开发模型】常用知识点
The round functions in the np, ceil function and floor function
shell学习
编译原理之文法
ACM MM 2022 | Cloud2Sketch: Painting with clouds in the sky, AI brush strokes
Let's talk about what DDL, DML, DQL and DCL are in SQL statements
Deceptive Dice
重要的不是成为海贼王,而是像路飞一样去冒险
js数组对象去重
unit test
SQLi-LABS Page-2 (Adv Injections)
mysql 找不到或无法加载已注册的 .Net Framework Data Provider。
Domestic mobile phone manufacturers once fought for it, but now it is the first to collapse...
在“企业通讯录”的盲区,融云的边界与分寸
Xiaohei's leetcode journey: 94. Inorder traversal of binary trees (supplementary Morris inorder traversal)