typedef long long LL; typedef unsigned long long ULL; const int maxn=1010; const int inf=0x7fffffff; const double eps=1e-3;
const int m1=0x00fc0000; const int m2=0x0003f000; const int m3=0x00000fc0; const int m4=0x0000003f;
char str[maxn];
char chs(char ch) { if (ch>=0&&ch<26) return ch+’A’; else if (ch>=26&&ch<52) return ch-26+’a’; else if (ch>=52&&ch<62) return ch-52+’0’; else if (ch==62) return ‘+’; else if (ch==63) return ‘/‘; }
void solve(char str[maxn]) { char s[maxn]={‘\0’}; int len=strlen(str); int tmp=0; int pos=0; for(int i=0;i<len;i++) { tmp<<=8;tmp+=int(str[i]); if (!((i+1)%3)) { s[pos++]=chs((tmp&m1)>>18); s[pos++]=chs(((tmp&m2)>>12)); s[pos++]=chs(((tmp&m3)>>6)); s[pos++]=chs((tmp&m4)); tmp=0; } } if (len%3) { tmp<<=(3-len%3)*8; if ((tmp&m1)>0) s[pos++]=chs((tmp&m1)>>18); if ((tmp&m2)>0) s[pos++]=chs(((tmp&m2)>>12)); if ((tmp&m3)>0) s[pos++]=chs(((tmp&m3)>>6)); if ((tmp&m4)>0) s[pos++]=chs((tmp&m4)); } int sum=4-strlen(s)%4; char *t=s+strlen(s); if (sum<4) for(int j=1;j<=sum;j++) *t++=’=’; *t=’\0’; strcpy(str,s); }
int main() { int T; scanf(“%d”,&T); while(T–) { int k; scanf(“%d%s”,&k,str); for(int i=1;i<=k;i++) solve(str); printf(“%s\n”,str); } return 0; } [/cpp]
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Problem Description
Given a string S and two integers L and M, we consider a substring of S as “recoverable” if and only if (i) It is of length M*L; (ii) It can be constructed by concatenating M “diversified” substrings of S, where each of these substrings has length L; two strings are considered as “diversified” if they don’t have the same character for every position.
Two substrings of S are considered as “different” if they are cut from different part of S. For example, string “aa” has 3 different substrings “aa”, “a” and “a”.
Your task is to calculate the number of different “recoverable” substrings of S.
Input
The input contains multiple test cases, proceeding to the End of File.
The first line of each test case has two space-separated integers M and L.
The second ine of each test case has a string S, which consists of only lowercase letters.
The length of S is not larger than 10^5, and 1 ≤ M * L ≤ the length of S.
Output
For each test case, output the answer in a single line.