BZOJ2268 : Wormly
考虑头部,一定是能向前就向前,因此是最左边的腿往右$b-1$个位置。
头部移动之后,腿部就要相应地移动到区间内最靠右的$l$个$1$之上。
若头部和腿部都不能移动,检查是否到达终点即可。
用前缀和以及对前缀和做映射来支持查询。
时间复杂度$O(n)$。
#include<cstdio>
const int N=1000010;
int T,l,b,n,i,h,f,nh,nf,s[N],p[N];char a[N];long long ans;
int main(){
scanf("%d",&T);
while(T--){
scanf("%d%d%d%s",&l,&b,&n,a+1);
for(i=1;i<=n;i++)if(a[i]=='0')s[i]=s[i-1];else p[s[i]=s[i-1]+1]=i;
ans=n-b,h=b,f=l;
while(1){
nh=p[s[f]-l+1]+b-1;
if(nh>n)nh=n;
nf=p[s[nh]];
if(nh==h&&nf==f)break;
h=nh;
if(nf>f)f=nf,ans+=l;
}
if(h<n)puts("IMPOSSIBLE");else printf("%lld\n",ans);
}
return 0;
}
BZOJ2268 : Wormly的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
随机推荐
- 该问题是需要导包!!!需要pom中添加依赖The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
<!-- https://mvnrepository.com/artifact/org.apache.taglibs/taglibs-standard-impl --><depend ...
- python编程实现十进制的转换(十进制到任何进制不用系统函数实现)
# 用户给定一个十进制数据,以及进制n, 完成n进制的转换,输出结果给用户(不要借助已有函数) # 用户的输入进制数据Decdata = int(input("请输入一个十进制数据:&quo ...
- SpringMVC - 1.快速入门
1. HelloWorld 步骤: 加入 jar 包 mons-logging-1.1.3.jar spring-aop-4.0.0.RELEASE.jar spring-beans-4.0.0.RE ...
- WPF 对控件进行截图且不丢失范围(转载)
原文:Taking WPF “Screenshots” I was recently working on a Surface project at Microsoft (that will be s ...
- php抽奖概率算法
方法一: function get_rand($proArr) { $result = array(); foreach ($proArr as $key => $val) { $arr[$ke ...
- Appearance-and-Relation Networks for Video Classification论文笔记 (ARTnet)
ARTnet: caffe实现:代码 1 Motivation:How to model appearance and relation (motion) 主要工作是在3D卷积的基础上,提升了acti ...
- 解决 Ionic 浏览器跨域问题
<system.webServer> <httpProtocol> <customHeaders> <add name="Access-Contro ...
- SQLALCHEMY_TRACK_MODIFICATIONS adds significant异常的解决方法
- 去掉select的原有样式
1:设置select的边框为0px,背景设成透明(background: transparent;),这时候你会看到边框没有了,但是小三角还是在的.再在select外面加个div,固定死div的宽度, ...
- 046 SparlSQL中的函数
一:SparkSQL中的函数 1.说明 2.展示所有的函数 qlContext.sql("show functions").show(300) 3.functions类 所有内置支 ...