/ tabris /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 3ms 340.0 KiB
#2 Accepted 5ms 320.0 KiB
#3 Accepted 5ms 256.0 KiB
#4 Accepted 2ms 340.0 KiB
#5 Accepted 3ms 348.0 KiB
#6 Accepted 50ms 1.25 MiB
#7 Accepted 55ms 1.418 MiB
#8 Accepted 65ms 1.379 MiB
#9 Accepted 57ms 1.34 MiB

代码

#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e6+5;
char s[maxn];
typedef long long ll;
ll k;

int main()
{
	int _;
	cin>>_;
	int ca = 1;
	while(_--)
	{
		scanf("%lld",&k);
		scanf("%s",s);
		if(k==0)
		{
			printf("Case #%d: 0\n",ca++);
			continue;
		}
		int len = strlen(s);
		ll ans = 0;
		for(int i = 0;i < len && i < k;++i)
		{
			ans = ans*2+(s[i]-'0');
		}
		ll sum = ans;
		for(int i = k;i < len;i++)
		{
			sum = (sum - (s[i-k]-'0')*(1ll << (k-1)))*2+(s[i]-'0');
			ans = max(ans,sum);
		}
		printf("Case #%d: %lld\n",ca++,ans);
	} 
	return 0;
}
/*
100
1
10101
1
10101
3
10101
5
10101
*/ 

信息

递交者
类型
递交
题目
幸运大奖
语言
C++
递交时间
2017-09-11 12:42:26
评测时间
2017-09-11 12:42:26
评测机
分数
576
总耗时
248ms
峰值内存
1.418 MiB