首页 技术 正文
技术 2022年11月20日
0 收藏 432 点赞 3,078 浏览 2527 个字

Vasya’s telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by swiping right from the last photo you reach photo 1. It takes a seconds to swipe from photo to adjacent.

For each photo it is known which orientation is intended for it — horizontal or vertical. Phone is in the vertical orientation and can’t be rotated. It takes b second to change orientation of the photo.

Vasya has T seconds to watch photos. He want to watch as many photos as possible. If Vasya opens the photo for the first time, he spends 1 second to notice all details in it. If photo is in the wrong orientation, he spends b seconds on rotating it before watching it. If Vasya has already opened the photo, he just skips it (so he doesn’t spend any time for watching it or for changing its orientation). It is not allowed to skip unseen photos.

Help Vasya find the maximum number of photos he is able to watch during T seconds.

Input

The first line of the input contains 4 integers n, a, b, T (1 ≤ n ≤ 5·105, 1 ≤ a, b ≤ 1000, 1 ≤ T ≤ 109) — the number of photos, time to move from a photo to adjacent, time to change orientation of a photo and time Vasya can spend for watching photo.

Second line of the input contains a string of length n containing symbols ‘w’ and ‘h’.

If the i-th position of a string contains ‘w’, then the photo i should be seen in the horizontal orientation.

If the i-th position of a string contains ‘h’, then the photo i should be seen in vertical orientation.

Output

Output the only integer, the maximum number of photos Vasya is able to watch during those T seconds.

ExamplesInput

4 2 3 10
wwhw

Output

2

Input

5 2 4 13
hhwhh

Output

4

Input

5 2 4 1000
hhwhh

Output

5

Input

3 1 100 10
whw

Output

0

Note

In the first sample test you can rotate the first photo (3 seconds), watch the first photo (1 seconds), move left (2 second), rotate fourth photo (3 seconds), watch fourth photo (1 second). The whole process takes exactly 10 seconds.

Note that in the last sample test the time is not enough even to watch the first photo, also you can’t skip it.

题意:给n张图片循环可看,每张图片的朝向为横(w)|竖(v),但是手机是竖直放置的。开始时打开的是第0张图片,如果一张图片为w放置就需先花b秒边把该张图片变成v朝向,从一张图片到下一张图片手机的反应时间为a秒,每观察一张图片需要1秒钟。不能直接跳过没看的图片,但是重新刷到看过的图片时,所花的时间只是手机的反应时间,不复看;问在t秒内能看的最多图片的数目为多少?

思路:预处理”看”每张图片所需的时间,即包括是否翻转;把总时间记录在sum中,并且由于可以从第0张开始顺序看和逆序看,直接弄成2*n的空间,把n当成原来的第0张,这样[l,r)就是所看的图片区间。线性处理[l,r]之间的时间即可;时间复杂度为O(n)

#include<bits/stdc++.h>
using namespace std;
typedef __int64 ll;
ll i,j,k,n,a,b,t,ans,cnt,sum;
const int N = 1e6+;
int w[N];
char s[N];
int main()
{
scanf("%d%d%d%d%s",&n,&a,&b,&t,s);
for(i = ;i < n;i++){
if(s[i] == 'w') w[i] = w[i+n] = b+;
else w[i] = w[i+n] = ;
sum += w[i];
}
sum -= w[];
ll l = ,r = n; // 以n = 0为起点,向左到l,向右到 r-1
while(l <= n && r < n+n){ // l = n表示只是顺序看图片
sum += w[r++];
while(r-l > n || sum+(r-l-+min(r--n,n-l))*a > t)
sum -= w[l++];
ans = max(ans,r-l);
}
cout<<ans;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,910
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,435
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,250
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,061
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,693
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,731