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. iis配置访问错误

    最近换工作,忙着熟悉新的环境,新的框架技术(银行用的EBF),各种碰坑. 总结一下iis配置过程当中遇到的一个坑------ 按照环境搭配手册一步一步的配置,在我机器上访问一直报500的错,但是同样的 ...

  2. [Web] Web请求过程之一:HTTP

    请求过程: 1.用户在浏览器输入 www.sdjtu.edu.cn 这个URL. 2.浏览器请求 DNS 服务器将这个 URL 解析成对应的 IP 地址. 3.浏览器向 IP 地址对应的这个服务器发起 ...

  3. bootstrap-switch与angularjs结合使用

    bootstrap-switch和angularjs结合使用 由于angularjs的dom操作总是先执行,导致$(input[name="switch"])找不到元素,所以使用d ...

  4. JS中浮点数精度误差解决

    问题出现 0.1 + 0.2 = 0.30000000000000004 问题分析 对于浮点数的四则运算,几乎所有的编程语言都会有类似精度误差的问题,只不过在 C++/C#/Java 这些语言中已经封 ...

  5. css3-自定义字体

    参考链接http://www.w3cplus.com/content/css3-font-face 出处W3CPLUS css3-自定义字体   @font-face @font-face是CSS3中 ...

  6. Java并发编程原理与实战七:线程带来的风险

    在并发中有两种方式,一是多进程,二是多线程,但是线程相比进程花销更小且能共享资源.但使用多线程同时会带来相应的风险,本文将展开讨论. 一.引言 多线程将会带来几个问题: 1.安全性问题 线程安全性可能 ...

  7. Java并发编程原理与实战二:并行&并发&多线程的理解

    1.CPU的发展趋势: 核心数目依旧会越来越多,根据摩尔定律,由于单个核心性能提升有着严重的瓶颈问题,普通的PC桌面在2018年可能回到24核心. 2.并发和并行的区别: 所有的并发处理都有排队等候, ...

  8. 经典全屏滚动插件fullPage.js

    要写简单可以写的很简单,对着github上面的参数和注释随便写了个demo.这个插件十分高端大气上档次,配上良好的配色和布局,简单几笔就可以把网站装扮得十分洋气. 唯一的缺点就是,感觉对移动端的兼容性 ...

  9. AngularJS - 下一个大框架

    AngularJS AngularJS是web应用的下一个巨头. AngularJS如果为创建web应用而设计,那它就是HTML的套路了.具有数据绑定, MVW, MVVM, MVC, 依赖注入的声明 ...

  10. HDU 2594 KMP

    题目链接 题意:给定两个字符串s1,s2,求最长的s1前缀s使得s为s2的最长后缀,输出该字符串和其长度. 题解:调换s1和s2的顺序,用KMP求解即可. #include <bits/stdc ...