C. Kamal-ol-molk's Painting
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Rumors say that one of Kamal-ol-molk's paintings has been altered. A rectangular brush has been moved right and down on the painting.

Consider the painting as a n × m rectangular grid. At the beginning an x × y rectangular brush is placed somewhere in the frame, with edges parallel to the frame, (1 ≤ x ≤ n, 1 ≤ y ≤ m). Then the brush is moved several times. Each time the brush is moved one unit right or down. The brush has been strictly inside the frame during the painting. The brush alters every cell it has covered at some moment.

You have found one of the old Kamal-ol-molk's paintings. You want to know if it's possible that it has been altered in described manner. If yes, you also want to know minimum possible area of the brush.

Input

The first line of input contains two integers n and m, (1 ≤ n, m ≤ 1000), denoting the height and width of the painting.

The next n lines contain the painting. Each line has m characters. Character 'X' denotes an altered cell, otherwise it's showed by '.'. There will be at least one altered cell in the painting.

Output

Print the minimum area of the brush in a line, if the painting is possibly altered, otherwise print  - 1.

Sample test(s)
input
4 4
XX..
XX..
XXXX
XXXX
output
4
input
4 4
....
.XXX
.XXX
....
output
2
input
4 5
XXXX.
XXXX.
.XX..
.XX..
output
-1

模拟即可,水题玩玩。代码能力略渣啊。。

#include <bits/stdc++.h>
using namespace std;
const int maxn = + ;
char g[maxn][maxn];
int n, m, minX, minY, ans;
int sum[maxn][maxn], cnt, tot;
int getSum(int a, int b, int x, int y) {
return sum[a][b] - sum[a][y + ] - sum[x + ][b] + sum[x + ][y + ];
}
bool ok(int a, int b, int posX = minX, int posY = minY) {
while() {
if(posX + a - > n || posY + b - > m) return false;
if(getSum(posX, posY, posX + a - , posY + b - ) != a * b) return false;
if(getSum(posX, posY, n, m) == a * b && getSum(posX, posY, posX + a - , posY + b - ) == a * b) {
return (cnt + a * b == tot) ;
}
bool flag1 = (a * b) == getSum(posX + , posY, posX + a, posY + b - );
bool flag2 = (a * b) == getSum(posX, posY + , posX + a - , posY + b);
if(!flag1 && !flag2) return false;
if(flag1 && flag2) return false;
if(flag1) ++posX, cnt += b;
else ++posY, cnt += a;
}
} int main() {
scanf("%d%d", &n, &m);
for(int i = ; i <= n; ++i) {
scanf("%s", g[i] + );
}
minX = n + , minY = m + ;
ans = n * m + ;
for(int i = n; < i; --i) {
for(int j = m; < j; --j) {
sum[i][j] = sum[i][j] - sum[i + ][j + ] + sum[i + ][j] + sum[i][j + ] + (g[i][j] == 'X');
if(g[i][j] == 'X') {
minX = min(i, minX), minY = min(j, minY);
++tot;
}
}
}
for(int i = ; i <= n; ++i) {
for(int j = ; j <= m; ++j) {
if(ans <= i * j) continue;
cnt = ;
if(ok(i, j)) ans = i * j;
}
}
printf("%d\n", ans == n * m + ? - : ans); return ;
}

CF475C. Kamal-ol-molk's Painting的更多相关文章

  1. OpenLayers 3 之 地图样式(ol.style)详解

    地图样式是由 style 类控制的,其包含了地图样式的方方面面,例如,填充色.图标样式.图片样式.规则图形样式.边界样式.文字样式等,样式一般针对矢量要素图层. 矢量图层样式可以事先写好,写成静态的, ...

  2. ul ol di三者区别

    1.ul是无序列表,也就是说没有排列限制可以随意加li: <ul> <li>可以随意放置</li> <li>可以随意放置</li> < ...

  3. HTML 列表 <ol><ul><li><dl><dt><dd>

    <ol>标签-有序列表 定义和用法: <ol>标签定义有序列表. HTML 与 XHTML 之间的差异 在 HTML 4.01 中,ol 元素的 "compact&q ...

  4. 语义化HTML:ul、ol和dl

    一.语义化元素   1. ul标签 W3C草案: The ul element represents an unordered list of items; that is, a list in wh ...

  5. CF448C Painting Fence (分治递归)

    Codeforces Round #256 (Div. 2) C C. Painting Fence time limit per test 1 second memory limit per tes ...

  6. HTML5 – 3.加强版ol

    <ol> 标签定义了一个有序列表. 列表排序以数字来显示. 使用<li> 标签来定义列表选项. 提示和注释 提示: 如果需要无序列表,请使用 <ul> 标签. 提示 ...

  7. ol新属性

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. [译]使用Continuous painting mode来分析页面的绘制状态

    Chrome Canary(Chrome “金丝雀版本”)目前已经支持Continuous painting mode,用于分析页面性能.这篇文章将会介绍怎么才能页面在绘制过程中找到问题和怎么利用这个 ...

  9. Codeforces Round #353 (Div. 2)Restoring Painting

    Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was sto ...

随机推荐

  1. JAVA 线程池基本总结

    合理利用线程池能够带来三个好处. 第一:降低资源消耗.通过重复利用已创建的线程降低线程创建和销毁造成的消耗. 第二:提高响应速度.当任务到达时,任务可以不需要等到线程创建就能立即执行. 第三:提高线程 ...

  2. PHP判断变量类型和类型转换的三种方式

    前言: PHP 在变量定义中不需要(不支持)明确的类型定义.变量类型是根据使用该变量的上下文所决定的.所以,在面对页码跳转.数值计算等严格的格式需求时,就要对变量进行类型转换. 举例如下: $foo ...

  3. HTML常用标签-<body>内基本标签(块级标签和内联标签)

    HTML常用标签-<body>内基本标签(块级标签和内联标签) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.<hn>系列标签 n的取值范围是1~6,从 ...

  4. Java基础-Date类常用方法介绍

    Java基础-Date类常用方法介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.毫秒值概念 我们在查阅Date类的API文档时,会发现这样的一句话:"The cl ...

  5. HTTP 错误 500.19 请求的页面的相关配置数据无效 解决办法

    "HTTP 错误 500.19 请求的页面的相关配置数据无效" 解决办法   HTTP 错误 500.19 - Internal Server Error无法访问请求的页面,因为该 ...

  6. javamail模拟邮箱功能获取邮件内容-中级实战篇【内容|附件下载方法】(javamail API电子邮件实例)

    引言: JavaMail jar包下载地址:http://java.sun.com/products/javamail/downloads/index.html 此篇是紧随上篇文章而封装出来的,阅读本 ...

  7. windows设置代理.bat 脚本

    按照下列脚本复制到记事本中,保存,重命名后缀为.bat,使用时双击即可. 设置代理.bat,修改下列脚本中的代理地址和端口号 @echo off echo 开始设置IE代理上网 reg add &qu ...

  8. Go学习中

    教程 http://www.runoob.com/go/go-slice.html Go语言中的管道(Channel)总结 http://www.cnblogs.com/yetuweiba/p/436 ...

  9. Bzoj4763 雪辉

    Time Limit: 39 Sec  Memory Limit: 666 MBSubmit: 151  Solved: 80 Description 上次立下的NOIP退役Flag没有成功   这次 ...

  10. Oracle DataTable的数据批量写入数据库

    insert语句,sqldataadapter.update(dataset,tablename);sqlbulkcopy.WriteToServer(datatable);三个方法的性能进行比较: ...