A8830 | Table with Letters - 2
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya has recently started to learn English. Now he needs to remember how to write English letters. He isn't sure about some of them, so he decided to train a little.
He found a sheet of squared paper and began writing arbitrary English letters there. In the end Vasya wrote $n$ lines containing $m$ characters each. Thus, he got a rectangular $n×m$ table, each cell of the table contained some English letter. Let's number the table rows from top to bottom with integers from 1 to $n$ , and columns — from left to right with integers from 1 to $m$ .
After that Vasya looked at the resulting rectangular table and wondered, how many subtables are there, that matches both following conditions:
- the subtable contains at most $k$ cells with "a" letter;
- all letters, located in all four corner cells of the subtable, are equal.
Formally, a subtable's definition is as follows. It is defined by four integers $x_{1},y_{1},x_{2},y_{2}$ such that $1<=x_{1}<x_{2}<=n$ , $1<=y_{1}<y_{2}<=m$ . Then the subtable contains all such cells $(x,y)$ ( $x$ is the row number, $y$ is the column number), for which the following inequality holds $x_{1}<=x<=x_{2},y_{1}<=y<=y_{2}$ . The corner cells of the table are cells $(x_{1},y_{1})$ , $(x_{1},y_{2})$ , $(x_{2},y_{1})$ , $(x_{2},y_{2})$ .
Vasya is already too tired after he's been writing letters to a piece of paper. That's why he asks you to count the value he is interested in.
He found a sheet of squared paper and began writing arbitrary English letters there. In the end Vasya wrote $n$ lines containing $m$ characters each. Thus, he got a rectangular $n×m$ table, each cell of the table contained some English letter. Let's number the table rows from top to bottom with integers from 1 to $n$ , and columns — from left to right with integers from 1 to $m$ .
After that Vasya looked at the resulting rectangular table and wondered, how many subtables are there, that matches both following conditions:
- the subtable contains at most $k$ cells with "a" letter;
- all letters, located in all four corner cells of the subtable, are equal.
Formally, a subtable's definition is as follows. It is defined by four integers $x_{1},y_{1},x_{2},y_{2}$ such that $1<=x_{1}<x_{2}<=n$ , $1<=y_{1}<y_{2}<=m$ . Then the subtable contains all such cells $(x,y)$ ( $x$ is the row number, $y$ is the column number), for which the following inequality holds $x_{1}<=x<=x_{2},y_{1}<=y<=y_{2}$ . The corner cells of the table are cells $(x_{1},y_{1})$ , $(x_{1},y_{2})$ , $(x_{2},y_{1})$ , $(x_{2},y_{2})$ .
Vasya is already too tired after he's been writing letters to a piece of paper. That's why he asks you to count the value he is interested in.
输入格式
The first line contains three integers $n,m,k$ $(2<=n,m<=400; 0<=k<=n·m)$ .
Next $n$ lines contain $m$ characters each — the given table. Each character of the table is a lowercase English letter.
Next $n$ lines contain $m$ characters each — the given table. Each character of the table is a lowercase English letter.
输出格式
Print a single integer — the number of required subtables.
输入输出样例
输入 #1
3 4 4 aabb baab baab
输出 #1
2
输入 #2
4 5 1 ababa ccaca ccacb cbabc
输出 #2
1
There are two suitable subtables in the first sample: the first one's upper left corner is cell $(2,2)$ and lower right corner is cell $(3,3)$ , the second one's upper left corner is cell $(2,1)$ and lower right corner is cell $(3,4)$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted