Codeforce 475 C. Kamal-ol-molk's Painting,kamalolmolk

來源:互聯網
上載者:User

Codeforce 475 C. Kamal-ol-molk's Painting,kamalolmolk


從最左上的點開始枚舉長寬....

C. Kamal-ol-molk's Paintingtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard 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 4XX..XX..XXXXXXXX
output
4
input
4 4.....XXX.XXX....
output
2
input
4 5XXXX.XXXX..XX...XX..
output
-1


#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;const int maxn=1100;const int INF=0x3f3f3f3f;char mp[maxn][maxn];int n,m,sum[maxn][maxn];int ans=INF;int area(int x1,int y1,int x2,int y2){return sum[x2][y2]-sum[x2][y1-1]-sum[x1-1][y2]+sum[x1-1][y1-1];}int dfs(int x,int y,int wx,int wy){if(area(x,y+1,x+wx-1,y+wy)==wx*wy) return wx+dfs(x,y+1,wx,wy);if(area(x+1,y,x+wx,y+wy-1)==wx*wy) return wy+dfs(x+1,y,wx,wy);return wx*wy;}int main(){scanf("%d%d",&n,&m);for(int i=1;i<=n;i++) scanf("%s",mp[i]+1);bool flag=false;int px=-1,py=-1;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){int t=0;if(mp[i][j]=='X'){if(flag==false){flag=true; px=i; py=j;}t=1;}sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+t;}}int temp=py;for(;temp<=m;temp++) if(mp[px][temp]!='X') break;int leny=temp-py;int lenx;for(int i=px;i<=n;i++){if(mp[i][py]!='X') break;lenx=i-px+1;if(dfs(px,py,lenx,leny)==sum[n][m]){ans=min(ans,lenx*leny);}}temp=px;for(;temp<=n;temp++) if(mp[temp][py]!='X') break;lenx=temp-px;for(int i=py;i<=m;i++){if(mp[px][i]!='X') break;leny=i-py+1;if(dfs(px,py,lenx,leny)==sum[n][m]){ans=min(ans,lenx*leny);}}if(ans==INF) ans=-1;printf("%d\n",ans);return 0;}



a number of -------are on in the museumLet's see them tomorrow Aworks Bpainting Cfilm Djobs

答案是A

沒錯,WORK 是不可數名詞,但作為著作時是可數;
A NUMBER OF 後接可數名詞複數,排除B與C ,根據句意: 許多……在博物館’ 應該是著作,而不是工作,再排除D,故正確答案是A

加油!不明白再問!如果幫到你,請採納,謝謝!
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.