codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

144C.md (2278B)


      1 Source: https://codeforces.com/problemset/problem/144/C
      2 
      3 C. Anagram Search
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 A string *t* is called an anagram of the string *s*, if it is possible to rearrange letters in *t* so that it is identical to the string *s*. For example, the string "aab" is an anagram of the string "aba" and the string "aaa" is not.
     22 
     23 The string *t* is called a substring of the string *s* if it can be read starting from some position in the string *s*. For example, the string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba".
     24 
     25 You are given a string *s*, consisting of lowercase Latin letters and characters "?". You are also given a string *p*, consisting of lowercase Latin letters only. Let's assume that a string is good if you can obtain an anagram of the string *p* from it, replacing the "?" characters by Latin letters. Each "?" can be replaced by exactly one character of the Latin alphabet. For example, if the string *p* = «aba», then the string "a??" is good, and the string «?bc» is not.
     26 
     27 Your task is to find the number of good substrings of the string *s* (identical substrings must be counted in the answer several times).
     28 
     29 Input
     30 
     31 The first line is non-empty string *s*, consisting of no more than 105 lowercase Latin letters and characters "?". The second line is non-empty string *p*, consisting of no more than 105 lowercase Latin letters. Please note that the length of the string *p* can exceed the length of the string *s*.
     32 
     33 Output
     34 
     35 Print the single number representing the number of good substrings of string *s*.
     36 
     37 Two substrings are considered different in their positions of occurrence are different. Thus, if some string occurs several times, then it should be counted the same number of times.
     38 
     39 Examples
     40 
     41 Input
     42 
     43 ```
     44 bb??x???  
     45 aab
     46 ```
     47 
     48 Output
     49 
     50 ```
     51 2
     52 ```
     53 
     54 Input
     55 
     56 ```
     57 ab?c  
     58 acb
     59 ```
     60 
     61 Output
     62 
     63 ```
     64 2
     65 ```
     66 
     67 Note
     68 
     69 Consider the first sample test. Here the string *s* has two good substrings: "b??" (after we replace the question marks we get "baa"), "???" (after we replace the question marks we get "baa").
     70 
     71 Let's consider the second sample test. Here the string *s* has two good substrings: "ab?" ("?" can be replaced by "c"), "b?c" ("?" can be replaced by "a").