Codeforces Round #345 (Div. 1) B. Image Preview

时间:2021-01-07 09:45:33

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.

Examples
Input
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;
}

Codeforces Round #345 (Div. 1) B. Image Preview的更多相关文章

  1. Codeforces Round &num;345 &lpar;Div&period; 2&rpar; D&period; Image Preview 暴力 二分

    D. Image Preview 题目连接: http://www.codeforces.com/contest/651/problem/D Description Vasya's telephone ...

  2. cf之路,1,Codeforces Round &num;345 &lpar;Div&period; 2&rpar;

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  3. Codeforces Round &num;345 &lpar;Div&period; 2&rpar;

    DFS A - Joysticks 嫌麻烦直接DFS暴搜吧,有坑点是当前电量<=1就不能再掉电,直接结束. #include <bits/stdc++.h> typedef long ...

  4. Codeforces Round &num;345 &lpar;Div&period; 2&rpar;【A&period;模拟,B,暴力,C,STL,容斥原理】

    A. Joysticks time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  5. Codeforces Round &num;345 &lpar;Div&period; 1&rpar; C&period; Table Compression dp&plus;并查集

    题目链接: http://codeforces.com/problemset/problem/650/C C. Table Compression time limit per test4 secon ...

  6. Codeforces Round &num;345 &lpar;Div&period; 1&rpar; E&period; Clockwork Bomb 并查集

    E. Clockwork Bomb 题目连接: http://www.codeforces.com/contest/650/problem/E Description My name is James ...

  7. Codeforces Round &num;345 &lpar;Div&period; 1&rpar; D&period; Zip-line 上升子序列 离线 离散化 线段树

    D. Zip-line 题目连接: http://www.codeforces.com/contest/650/problem/D Description Vasya has decided to b ...

  8. Codeforces Round &num;345 &lpar;Div&period; 2&rpar; E&period; Table Compression 并查集

    E. Table Compression 题目连接: http://www.codeforces.com/contest/651/problem/E Description Little Petya ...

  9. Codeforces Round &num;345 &lpar;Div&period; 1&rpar; A - Watchmen 容斥

    C. Watchmen 题目连接: http://www.codeforces.com/contest/651/problem/C Description Watchmen are in a dang ...

随机推荐

  1. easyui datagird 列宽自适应

    代码如下: onLoadSuccess: function (data) { var rows = data.rows; //得到行数据 var columnMaxCharacter = new Ar ...

  2. Objective-C实现发短信和接电话

    发短信: [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms://10000"]]; 打电话: ...

  3. 创建一个应用台程序,声明一个 int变量,并且初始化数组,通过while语句输出数组内的所有成员。

    ]{,,,,}; ; ) { Console.WriteLine("myNum[{0}]的值为{1}", s,myNum[s]); s++; } Console.ReadLine( ...

  4. java中判断一个字符串是否&OpenCurlyDoubleQuote;都为数字”和&OpenCurlyDoubleQuote;是否包含数字”和&OpenCurlyDoubleQuote;截取数字”

    在javascript中有一个方法isDigit()使用来判断一个字符串是否都是数字,在java的字符串处理方法中没有这样的方法,觉得常常需要用到,于是上网搜了一下,整理出了两个用正则表达式匹配的判断 ...

  5. HDU 1494 跑跑卡丁车

    很无爱的一道题. 题解都看得一知半解的. acm之家的题解,留着以后慢慢体会: 把这题转化为背包模型,每个%20能量算一个单位,最多有15个,如果大于5个有一个加速卡,如果大于10个有2个加速卡,如果 ...

  6. &lbrack;Android&rsqb;Handler的消息机制

    最经面试中,技术面试中有一个是Handler的消息机制,细细想想,我经常用到的Handler无非是在主线程(或者说Activity)新建一个Handler对象,另外一个Thread是异步加载数据,同时 ...

  7. 【转】android获取屏幕宽度和高度

    原文网址:http://www.cnblogs.com/howlaa/p/4123186.html 1. WindowManager wm = (WindowManager) getContext() ...

  8. 霍夫曼(最优二叉树)和Java达到

    一.定义 一些定义: 节点之间的路径长度:在从节点树中的一个节点也经历分公司,这构成的两个节点之间的路径分支的数目后这就是所谓的路径长度 的路径长度:从树的根节点到树中每一结点的路径长度之和. 在结点 ...

  9. mysql 省市联动sql 语句

    /*MySQL Data TransferSource Host: localhostSource Database: virgoTarget Host: localhostTarget Databa ...

  10. 【C&plus;&plus; STL】Set和Multiset

    1.结构 set和multiset会根据特定的排序原则将元素排序.两者不同之处在于,multisets允许元素重复,而set不允许重复. 只要是assignable.copyable.comparab ...