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