Codeforces Round #345 (Div. 2) D Detail questions

Source: Internet
Author: User

The meaning of this problem is to give you a photo of the end-to-end, the current photo in 1, can only transfer a unit, the transfer time is a, the picture may be reversed, the picture will need to be the time to B, look at the photo of the time is 1, want to see as many photos, ask the number is how much, We can preprocess the time required to view each photo, and then enumerate the time needed from the left, looking at the time required from the right, and two points looking at the time required from the other side, the code is as follows:

#include <cstdio>#include<algorithm>#include<cstring>using namespacestd;intN, a, b, T;Chars[500000+Ten];Long Longd[500000+Ten], d1[500000+Ten];intMain () {scanf ("%d%d%d%d", &n, &a, &b, &T); scanf ("%s", s+1);  for(intI=1; i<=n; i++)        if(S[i] = ='W') D[i] = d[i-1] + B +1; ElseD[i] = d[i-1] +1;  for(intI=n; i>=1; i--)        if(S[i] = ='W') D1[i] = d1[i+1] + B +1; ElseD1[i] = d1[i+1] +1; intres =0;  for(intI=1; i<=n; i++)    {        //1-I        intT1 = t-d[i]-(i1)*A; if(T1 <0) Break; Res=Max (res, i); T1-= (-1)*A; if(t1<0)Continue; intl=i+1, r=N; intTPR = r+1;  while(L <=r) {intMid = (l+r)/2; if(T1-(n-mid+1) *a+d1[mid]) <0) L = mid +1; Else{R= Mid-1; TPR=mid; }} Res= Max (res, i+n-tpr+1); }     for(intI=n; i>=2; i--)    {        intT1 = T-(n-i+1) *a-d1[i]-d[1]; if(T1 <0) Break; Res= Max (res, n-i+2); T1-= (n-i+1)*A; if(T1 <0)Continue; intL=2, r=i-1; intTPR =1;  while(L <=r) {intMid = (l+r)/2; if(T1-(mid-1) *a+d[mid]-d[1]) <0) R = Mid-1; Else{TPR=mid; L= Mid +1; }} Res= Max (res, tpr+n-i+1); } printf ("%d\n", RES); return 0;}

Codeforces Round #345 (Div. 2) D Detail questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.