A8460 | Anagram Search
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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".
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.
Your task is to find the number of good substrings of the string $s$ (identical substrings must be counted in the answer several times).
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".
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.
Your task is to find the number of good substrings of the string $s$ (identical substrings must be counted in the answer several times).
输入格式
The first line is non-empty string $s$ , consisting of no more than $10^{5}$ lowercase Latin letters and characters "?". The second line is non-empty string $p$ , consisting of no more than $10^{5}$ lowercase Latin letters. Please note that the length of the string $p$ can exceed the length of the string $s$ .
输出格式
Print the single number representing the number of good substrings of string $s$ .
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.
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.
输入输出样例
输入 #1
bb??x??? aab
输出 #1
2
输入 #2
ab?c acb
输出 #2
2
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").
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").
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").
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted