답안 #697229

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697229 2023-02-09T00:06:32 Z allllekssssa Bomb (IZhO17_bomb) C++14
37 / 100
1000 ms 53272 KB
#include<bits/stdc++.h>

using namespace std;

const int maxN = 2600;
int n, m;
int a[maxN][maxN];
int d[maxN][maxN];
int c[maxN][maxN];
string s;

int getDSum(int x1, int y1, int x2, int y2) {
	if (x2 > n || y2 > m) return 0;
	return d[x2][y2] + d[x1 - 1][y1 - 1] - d[x1 - 1][y2] - d[x2][y1 - 1];
}

int getCSum(int x1, int y1, int x2, int y2) {
	x1 = max(x1, 1);
	y1 = max(y1, 1);
	return c[x2][y2] + c[x1 - 1][y1 - 1] - c[x1 - 1][y2] - c[x2][y1 - 1];
}

bool check(int x, int y) {

	for (int i = 1; i<=n; i++) {
		for (int j = 1; j<=m; j++) {
			c[i][j] = 0;
		}
	}
   
   for (int i = 1; i<=n; i++) {
   	 for (int j = 1; j<=m; j++) {
   	 	if (getDSum(i, j, i + x - 1, j + y - 1) == x * y) c[i][j] = 1;
   	 }
   }

   for (int i = 1; i <= n; i++) {
		for (int j = 1; j<=m; j++) {
			c[i][j] += c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1];
		}
	}

   for (int i = 1; i<=n; i++) {
   	for (int j = 1; j <= m; j++) {
 		  if (a[i][j] && getCSum(i - x + 1, j - y + 1, i, j) == 0) return false;
   	  }
   }

   return true;
}


int heuristic() {
  
   int minW = n;
   int minH = m;

	for (int i = 1; i<=n; i++) {
		int cur = 0;
		for (int j = 1; j<=m; j++) {
			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 j = 1; j<=m; j++) {
		int cur = 0;
		for (int i = 1; i<=n; i++) {
			if (a[i][j] == 1) cur++; else {
				if (cur > 0) {
					minW = min(minW, cur);
					cur = 0;
				}
			}
		}

		if (cur > 0) minW = min(minW, cur);
	}
    
    int ans = 0;
	for (int i = 0; i< min(8, minW); i++) {
		for (int j = 0; j<min(8, minH); j++) {
           if (check(minW - i, minH -j)) ans = max(ans, (minW - i) * (minH -j));
		}
	}
	return ans;
}


int main() {

	cin >> n >> m;

	for (int i = 1; i <=n; i++) {
		cin >> s;

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

	if (n >= 500 || m >= 500) {
		cout << heuristic() << endl;
		return 0;
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j<=m; j++) {
			d[i][j] = d[i - 1][j] + d[i][j - 1] + a[i][j] - d[i - 1][j - 1];
		}
	}
   
    int ans = 0;
    
    int width = m;
	for (int i = 1; i <=n; i++) {

		while (width > 0 && !check(i, width)) width--;

		ans = max(ans, i * width);
	}
    
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Incorrect 11 ms 20436 KB Output isn't correct
4 Incorrect 11 ms 20436 KB Output isn't correct
5 Incorrect 1 ms 340 KB Output isn't correct
6 Incorrect 1 ms 212 KB Output isn't correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 568 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 3 ms 1108 KB Output is correct
18 Correct 2 ms 1108 KB Output is correct
19 Correct 6 ms 1492 KB Output is correct
20 Correct 6 ms 1520 KB Output is correct
21 Correct 4 ms 980 KB Output is correct
22 Correct 6 ms 1216 KB Output is correct
23 Correct 9 ms 1596 KB Output is correct
24 Correct 5 ms 1376 KB Output is correct
25 Correct 10 ms 1636 KB Output is correct
26 Correct 11 ms 1600 KB Output is correct
27 Correct 139 ms 4820 KB Output is correct
28 Correct 263 ms 5196 KB Output is correct
29 Correct 337 ms 6572 KB Output is correct
30 Correct 682 ms 7868 KB Output is correct
31 Correct 513 ms 6228 KB Output is correct
32 Correct 608 ms 7148 KB Output is correct
33 Correct 834 ms 8284 KB Output is correct
34 Correct 118 ms 5588 KB Output is correct
35 Correct 583 ms 8280 KB Output is correct
36 Correct 833 ms 8284 KB Output is correct
37 Correct 1 ms 468 KB Output is correct
38 Execution timed out 1032 ms 52116 KB Time limit exceeded
39 Correct 1 ms 468 KB Output is correct
40 Incorrect 307 ms 13620 KB Output isn't correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 12 ms 1620 KB Output is correct
43 Execution timed out 1104 ms 52260 KB Time limit exceeded
44 Correct 965 ms 8284 KB Output is correct
45 Execution timed out 1020 ms 52280 KB Time limit exceeded
46 Execution timed out 1105 ms 52260 KB Time limit exceeded
47 Execution timed out 1092 ms 52208 KB Time limit exceeded
48 Execution timed out 1022 ms 52172 KB Time limit exceeded
49 Execution timed out 1098 ms 52248 KB Time limit exceeded
50 Execution timed out 1018 ms 52260 KB Time limit exceeded
51 Execution timed out 1039 ms 52172 KB Time limit exceeded
52 Execution timed out 1059 ms 52200 KB Time limit exceeded
53 Execution timed out 1092 ms 52296 KB Time limit exceeded
54 Execution timed out 1072 ms 52280 KB Time limit exceeded
55 Execution timed out 1086 ms 52284 KB Time limit exceeded
56 Execution timed out 1098 ms 52400 KB Time limit exceeded
57 Execution timed out 1070 ms 53272 KB Time limit exceeded
58 Execution timed out 1088 ms 53252 KB Time limit exceeded
59 Execution timed out 1085 ms 53256 KB Time limit exceeded
60 Execution timed out 1072 ms 53152 KB Time limit exceeded
61 Execution timed out 1061 ms 53248 KB Time limit exceeded
62 Execution timed out 1100 ms 53268 KB Time limit exceeded
63 Execution timed out 1084 ms 53252 KB Time limit exceeded
64 Execution timed out 1010 ms 53252 KB Time limit exceeded
65 Execution timed out 1022 ms 53240 KB Time limit exceeded
66 Execution timed out 1035 ms 53124 KB Time limit exceeded
67 Execution timed out 1083 ms 52472 KB Time limit exceeded
68 Execution timed out 1028 ms 52000 KB Time limit exceeded
69 Execution timed out 1077 ms 52104 KB Time limit exceeded
70 Execution timed out 1063 ms 41544 KB Time limit exceeded
71 Execution timed out 1010 ms 52100 KB Time limit exceeded
72 Execution timed out 1054 ms 52032 KB Time limit exceeded
73 Execution timed out 1024 ms 52104 KB Time limit exceeded
74 Execution timed out 1049 ms 52096 KB Time limit exceeded
75 Execution timed out 1090 ms 52100 KB Time limit exceeded
76 Execution timed out 1077 ms 52004 KB Time limit exceeded
77 Execution timed out 1103 ms 52096 KB Time limit exceeded
78 Execution timed out 1025 ms 52048 KB Time limit exceeded
79 Execution timed out 1029 ms 52104 KB Time limit exceeded
80 Execution timed out 1063 ms 52044 KB Time limit exceeded
81 Execution timed out 1057 ms 51916 KB Time limit exceeded
82 Execution timed out 1045 ms 51984 KB Time limit exceeded
83 Execution timed out 1048 ms 51944 KB Time limit exceeded
84 Execution timed out 1060 ms 52176 KB Time limit exceeded
85 Execution timed out 1022 ms 51908 KB Time limit exceeded
86 Execution timed out 1066 ms 51984 KB Time limit exceeded
87 Execution timed out 1036 ms 51984 KB Time limit exceeded
88 Execution timed out 1064 ms 51988 KB Time limit exceeded
89 Execution timed out 1070 ms 51960 KB Time limit exceeded
90 Execution timed out 1006 ms 41296 KB Time limit exceeded
91 Execution timed out 1094 ms 51208 KB Time limit exceeded
92 Execution timed out 1097 ms 51144 KB Time limit exceeded
93 Execution timed out 1095 ms 51148 KB Time limit exceeded
94 Execution timed out 1081 ms 51276 KB Time limit exceeded
95 Execution timed out 1090 ms 51224 KB Time limit exceeded
96 Execution timed out 1069 ms 51204 KB Time limit exceeded
97 Execution timed out 1095 ms 51148 KB Time limit exceeded
98 Execution timed out 1094 ms 51204 KB Time limit exceeded
99 Execution timed out 1093 ms 51328 KB Time limit exceeded
100 Execution timed out 1082 ms 51272 KB Time limit exceeded