답안 #334693

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334693 2020-12-09T19:26:54 Z limabeans Bomb (IZhO17_bomb) C++17
100 / 100
445 ms 76012 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl








const int maxn = 2555;
const int inf = 1e9;


int n,m;
int a[maxn][maxn];

int up[maxn][maxn], dw[maxn][maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    cin>>n>>m;
    for (int i=0; i<n; i++) {
	string s;
	cin>>s;
	for (int j=0; j<m; j++) {
	    a[i][j]=int(s[j]-'0');
	}
    }


    for (int j=0; j<m; j++) {
	for (int i=0; i<n; i++) {
	    if (a[i][j]==1) {
		up[i][j]=1;
		if (i>0) up[i][j]+=up[i-1][j];
	    }
	}
	for (int i=n-1; i>=0; i--) {
	    if (a[i][j]==1) {
		dw[i][j]=1;
		dw[i][j]+=dw[i+1][j];
	    }
	}
    }


    int minW = inf;
    int minH = inf;
    for (int j=0; j<m; j++) {
	int cur = 0;
	for (int i=0; i<n; i++) {
	    if (a[i][j]==1) {
		cur++;
	    } else {
		if (cur>0) minH=min(minH,cur);
		cur=0;
	    }
	}
	if (cur>0) minH=min(minH,cur);
    }


    for (int i=0; i<n; i++) {
	int cur = 0;
	for (int j=0; j<m; j++) {
	    if (a[i][j]) {
		cur++;
	    } else {
		if (cur>0) minW=min(minW,cur);
		cur=0;
	    }
	}
	if (cur>0) minW=min(minW,cur);
    }


    // watch(minW);
    // watch(minH);

    vector<int> dp(maxn+10, minH); //dp[w]: given width w, what's feasible height h for rectangle hxw

    // left to right
    for (int i=0; i<n; i++) {
	int u=inf;
	int d=inf;
	int col=0;
	for (int j=0; j<m; j++) {
	    if (a[i][j]==1) {
		u=min(u,up[i][j]);
		d=min(d,dw[i][j]);
		++col;
		dp[col]=min(dp[col],u+d-1);
	    } else {
		u=d=inf;
		col=0;
	    }
	}
    }

    // right to left
    for (int i=0; i<n; i++) {
	int u=inf;
	int d=inf;
	int col=0;
	for (int j=m-1; j>=0; j--) {
	    if (a[i][j]==1) {
		u=min(u,up[i][j]);
		d=min(d,dw[i][j]);
		++col;
		dp[col]=min(dp[col],u+d-1);
	    } else {
		u=d=inf;
		col=0;
	    }
	}
    }

    int res = dp[1];
    for (int i=2; i<=minW; i++) {
	dp[i]=min(dp[i],dp[i-1]);
	res=max(res,i*dp[i]);
    }

    cout<<res<<endl;    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 16 ms 30444 KB Output is correct
4 Correct 17 ms 30572 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 1 ms 1132 KB Output is correct
18 Correct 1 ms 1004 KB Output is correct
19 Correct 1 ms 1260 KB Output is correct
20 Correct 1 ms 1260 KB Output is correct
21 Correct 1 ms 748 KB Output is correct
22 Correct 1 ms 1004 KB Output is correct
23 Correct 1 ms 1260 KB Output is correct
24 Correct 1 ms 1132 KB Output is correct
25 Correct 1 ms 1516 KB Output is correct
26 Correct 1 ms 1644 KB Output is correct
27 Correct 5 ms 4844 KB Output is correct
28 Correct 3 ms 2412 KB Output is correct
29 Correct 7 ms 6380 KB Output is correct
30 Correct 6 ms 5740 KB Output is correct
31 Correct 4 ms 4332 KB Output is correct
32 Correct 5 ms 5484 KB Output is correct
33 Correct 7 ms 6892 KB Output is correct
34 Correct 3 ms 2796 KB Output is correct
35 Correct 4 ms 3820 KB Output is correct
36 Correct 12 ms 8428 KB Output is correct
37 Correct 1 ms 620 KB Output is correct
38 Correct 439 ms 75884 KB Output is correct
39 Correct 1 ms 620 KB Output is correct
40 Correct 54 ms 20204 KB Output is correct
41 Correct 1 ms 620 KB Output is correct
42 Correct 2 ms 1644 KB Output is correct
43 Correct 378 ms 71276 KB Output is correct
44 Correct 8 ms 7788 KB Output is correct
45 Correct 370 ms 72556 KB Output is correct
46 Correct 362 ms 75884 KB Output is correct
47 Correct 369 ms 72812 KB Output is correct
48 Correct 352 ms 76012 KB Output is correct
49 Correct 445 ms 75756 KB Output is correct
50 Correct 362 ms 75756 KB Output is correct
51 Correct 366 ms 75772 KB Output is correct
52 Correct 360 ms 75780 KB Output is correct
53 Correct 359 ms 74988 KB Output is correct
54 Correct 298 ms 61932 KB Output is correct
55 Correct 294 ms 60012 KB Output is correct
56 Correct 443 ms 75756 KB Output is correct
57 Correct 286 ms 54648 KB Output is correct
58 Correct 294 ms 59884 KB Output is correct
59 Correct 298 ms 56556 KB Output is correct
60 Correct 344 ms 67692 KB Output is correct
61 Correct 444 ms 75884 KB Output is correct
62 Correct 440 ms 75756 KB Output is correct
63 Correct 442 ms 76012 KB Output is correct
64 Correct 313 ms 58692 KB Output is correct
65 Correct 347 ms 74604 KB Output is correct
66 Correct 359 ms 70636 KB Output is correct
67 Correct 367 ms 75756 KB Output is correct
68 Correct 377 ms 75756 KB Output is correct
69 Correct 286 ms 54380 KB Output is correct
70 Correct 160 ms 30744 KB Output is correct
71 Correct 260 ms 47468 KB Output is correct
72 Correct 281 ms 53100 KB Output is correct
73 Correct 287 ms 53356 KB Output is correct
74 Correct 284 ms 54892 KB Output is correct
75 Correct 288 ms 56428 KB Output is correct
76 Correct 299 ms 57964 KB Output is correct
77 Correct 300 ms 58348 KB Output is correct
78 Correct 307 ms 58540 KB Output is correct
79 Correct 218 ms 31084 KB Output is correct
80 Correct 216 ms 32236 KB Output is correct
81 Correct 223 ms 32620 KB Output is correct
82 Correct 304 ms 61036 KB Output is correct
83 Correct 300 ms 61164 KB Output is correct
84 Correct 213 ms 26348 KB Output is correct
85 Correct 297 ms 60140 KB Output is correct
86 Correct 421 ms 74604 KB Output is correct
87 Correct 289 ms 58860 KB Output is correct
88 Correct 300 ms 59884 KB Output is correct
89 Correct 339 ms 69228 KB Output is correct
90 Correct 191 ms 45036 KB Output is correct
91 Correct 319 ms 63980 KB Output is correct
92 Correct 337 ms 66284 KB Output is correct
93 Correct 416 ms 73836 KB Output is correct
94 Correct 336 ms 68076 KB Output is correct
95 Correct 301 ms 61292 KB Output is correct
96 Correct 304 ms 61164 KB Output is correct
97 Correct 417 ms 74476 KB Output is correct
98 Correct 302 ms 61020 KB Output is correct
99 Correct 332 ms 67564 KB Output is correct
100 Correct 413 ms 73452 KB Output is correct