暴力水过,剪一下枝= =果断是数据水了
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #define LL __int64 5 using namespace std; 6 7 const int MAXN=111111; 8 char str[MAXN]; 9 10 int same(int a,int b,int x,int y) 11 { 12 if(a==x) 13 return min(b,y)-a; 14 int i=0; 15 while((a+i)<b&&(x+i)<y&&str[a+i]==str[x+i]) 16 i++; 17 return i; 18 } 19 20 int num(int x) 21 { 22 if(!x)return 1; 23 int ans=0; 24 while(x!=0) 25 { 26 ans++; 27 x/=10; 28 } 29 return ans; 30 } 31 32 int main() 33 { 34 int n,a,b,x,y,q,p; 35 while(~scanf("%s",str)) 36 { 37 scanf("%d",&n); 38 LL s,t; 39 s=t=0; 40 for(int i=0;i<n;i++) 41 { 42 scanf("%d%d",&a,&b); 43 if(i!=0)q=same(a,b,x,y); 44 else q=0; 45 p=num(q); 46 s+=b-a+1; 47 t+=p+1+b-a-q+1; 48 x=a;y=b; 49 } 50 printf("%I64d %I64d ",s,t); 51 } 52 return 0; 53 }