# loj2734「JOISC 2016 Day 2」女⁯装大佬 || 洛谷P3615 如厕计划

loj2734

http://218.5.5.242:9021/problem/185

F>=M-1,M<=F+1
S=F+M>=2M-1
<=2F+1

F>=(S-1)/2

S:F>=[S/2]

F在小串中的位置：A[1..6]从小到大

a+1,b+L-A[6]+1,2a+2,2a+2-(b+L-A[6]+1)
a+2,b+L-A[5]+1,2a+4,2a+4-(b+L-A[5]+1)
...
a+6,b+L-A[1]+1,2a+12

a+6k-5,b+Lk-A[6]+1,2a+12k-10,2a+12k-10-(b+Lk-A[6]+1)

2a-10-b+A[6]-1+(12-L)k
12=2a
2a-L>0 -->

2(a+F)-(b+Lk-pos+1)

a+N(k-1)+F,b+Lk-pos,2a+2N(k-1)+2F,
(2N-L)k+2a-2N+2F-b+pos

a+N(k-1)+F,b+Lk-pos,2a+2N(k-1)+2F,
2a+(2N-L)k-2N+2F-b+j

a=0,b=2
k,k+2,k-2

 1 #include<cstdio>
2 #include<algorithm>
3 #include<cstring>
4 #include<vector>
5 using namespace std;
6 #define fi first
7 #define se second
8 #define mp make_pair
9 #define pb push_back
10 typedef long long ll;
11 typedef unsigned long long ull;
12 ll n,m;
13 char dattt[400011],*st=dattt,*s[200011];
14 ll len[200011],x[200011],anss;
15 int main()
16 {
17     ll i,j,a=0,b=0,N,F,tt;
18     scanf("%lld",&n);
19     scanf("%lld",&m);
20     for(i=1;i<=m;++i)
21     {
22         s[i]=st;
23         scanf("%s%lld",st,x+i);
24         len[i]=strlen(st);
25         st+=len[i]+1;
26     }
27     tt=0;
28     for(i=1;i<=m;++i)
29     {
30         F=0;
31         for(j=0;j<len[i];++j)
32             F+=s[i][j]=='F';
33         tt+=F*x[i];
34     }
35     if(tt<n)
36     {
37         puts("-1");
38         return 0;
39     }
40     for(i=m;i>=1;--i)
41     {
42         F=0;N=0;
43         for(j=len[i]-1;j>=0;--j)
44             N+=s[i][j]=='F';
45         if(2*N-len[i]<0)
46         {
47             for(j=len[i]-1;j>=0;--j)
48             {
49                 if(s[i][j]=='F')
50                 {
51                     ++F;
52                     anss=max(anss,-((2*N-len[i])*x[i]+2*a-2*N+2*F-b+j));
53                 }
54             }
55         }
56         else
57         {
58             for(j=len[i]-1;j>=0;--j)
59             {
60                 if(s[i][j]=='F')
61                 {
62                     ++F;
63                     anss=max(anss,-(-len[i]+2*a+2*F-b+j));
64                 }
65             }
66         }
67         a+=F*x[i];
68         b+=len[i]*x[i];
69     }
70     printf("%lld",anss);
71     return 0;
72 }
View Code

posted @ 2019-02-21 21:34  hehe_54321  阅读(584)  评论(0编辑  收藏  举报