3725:pa2014 Final matryca time limit:5 Sec Memory limit:128 MB
submit:160 solved:96
[Submit] [Status] [Discuss] Description
There is a wall of length n to paint, you have a brush of length k. The walls and brushes are evenly divided into small units of length, and each of the brushes is stained with a certain color (solid color). You need to use this brush in every possible position on the wall (as long as the brush does not go beyond the wall and is aligned to the grid; there are n-k+1 locations). If one of the walls is painted with a different color, it will show a mixed color.
Now some squares on the wall need to be painted in a given color. Find the shortest brush length k to complete the task.
Input
The input is a string of length n (1<=n<=1000000), consisting of uppercase letters and asterisks. An uppercase letter indicates a solid color, and an asterisk indicates that the position color is not required.
Output
Outputs the smallest k.
Sample Inputa*b*b*aSample Output6HINT
Explain:
The color of the brush is Abbbba.
Source
Acknowledgement JCVB
Solution
Brain hole, nothing to say.
The answer is len-mindis+1.
Len is the length of the string, Mindis is the shortest distance of the adjacent non-different colors
Consider this:
If, so the color must be solid color, and 22 different, then obviously the brush is N, then if the different color adjacent to the nearest 2, then obviously brush brush for n-2+1
Similarly.....
Code
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;#defineMAXN 1000010CharS[maxn],a;intL,n,a,dis;intMain () {scanf ("%s", s+1); N=strlen (s+1); A='&'; dis=N; for(intI=1; i<=n; i++) if(s[i]!='*') { if(a=='&') a=s[i],a=i; Else if(a!=S[i]) {Dis=min (dis,i-a); A=i,a=S[i]; } ElseA=i; } printf ("%d\n", n-dis+1); return 0;}
"BZOJ-3725" Matryca wtf