Submission #697251

# Submission time Handle Problem Language Result Execution time Memory
697251 2023-02-09T01:15:16 Z allllekssssa Bomb (IZhO17_bomb) C++14
5 / 100
1000 ms 76668 KB
#include<bits/stdc++.h>
 
using namespace std;


#define pii pair<int ,int>
#define pb push_back

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

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 heuristic1() {

	vector<pii> gornji;

	for (int i = 1; i<=n; i++) {
		for (int j = 1; j<=m; j++) {
			if (a[i - 1][j] == 0 && a[i][j - 1] == 0) gornji.pb({i, j});
		}
	}

	random_shuffle(gornji.begin(), gornji.end());
    
    for (int i = 1; i <=n; i++) {
    	cnt[i] = m;
    }

    for (int i = 0; i < min(200, (int) gornji.size()); i++) {
       for (int len = 1; len <= n; len++) {
          
          int x = gornji[i].first;
          int y = gornji[i].second;

       	  int lo = -1;
       	  int ro = m + 1;
 
       	  while(lo < ro - 1) {
       	  	 int mid = lo + ro >> 1;
       	  	 if (getDSum(x, y, x + len - 1, y + mid - 1) == len * mid) lo = mid; else ro = mid;
       	  }

       	  cnt[len] = min(cnt[len], lo);
       }
    }


    int ans = 0;
    for (int i = 1; i<=n; i++) {
    	ans = max(ans, i * cnt[i]);
    }

    return ans;
}
 
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 = minW * minH;
    if (!check(minW, minH)) return heuristic1();
	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';
		}
	}
    
    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];
		}
	}

	if (n <= 450 && m <= 450) {
		cout << heuristic1() << endl;
		return 0;
	}

   
    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;
}

Compilation message

bomb.cpp: In function 'int heuristic1()':
bomb.cpp:83:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   83 |             int mid = lo + ro >> 1;
      |                       ~~~^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Incorrect 0 ms 468 KB Output isn't correct
3 Correct 17 ms 30444 KB Output is correct
4 Correct 19 ms 30420 KB Output is correct
5 Correct 35 ms 344 KB Output is correct
6 Correct 6 ms 340 KB Output is correct
7 Incorrect 0 ms 340 KB Output isn't correct
8 Incorrect 0 ms 468 KB Output isn't correct
9 Incorrect 1 ms 468 KB Output isn't correct
10 Incorrect 0 ms 340 KB Output isn't correct
11 Incorrect 1 ms 468 KB Output isn't correct
12 Incorrect 0 ms 340 KB Output isn't correct
13 Incorrect 1 ms 340 KB Output isn't correct
14 Incorrect 1 ms 340 KB Output isn't correct
15 Incorrect 0 ms 468 KB Output isn't correct
16 Correct 1 ms 468 KB Output is correct
17 Incorrect 1 ms 852 KB Output isn't correct
18 Incorrect 1 ms 980 KB Output isn't correct
19 Incorrect 1 ms 1236 KB Output isn't correct
20 Incorrect 2 ms 1236 KB Output isn't correct
21 Incorrect 1 ms 852 KB Output isn't correct
22 Incorrect 1 ms 980 KB Output isn't correct
23 Incorrect 2 ms 1236 KB Output isn't correct
24 Incorrect 1 ms 1108 KB Output isn't correct
25 Incorrect 2 ms 1236 KB Output isn't correct
26 Incorrect 1 ms 1108 KB Output isn't correct
27 Incorrect 3 ms 3284 KB Output isn't correct
28 Incorrect 9 ms 4556 KB Output isn't correct
29 Incorrect 7 ms 4820 KB Output isn't correct
30 Incorrect 13 ms 7368 KB Output isn't correct
31 Incorrect 10 ms 5324 KB Output isn't correct
32 Incorrect 12 ms 6856 KB Output isn't correct
33 Incorrect 14 ms 7668 KB Output isn't correct
34 Incorrect 8 ms 4940 KB Output isn't correct
35 Incorrect 16 ms 7580 KB Output isn't correct
36 Incorrect 7 ms 5460 KB Output isn't correct
37 Incorrect 1 ms 468 KB Output isn't correct
38 Execution timed out 1094 ms 76620 KB Time limit exceeded
39 Incorrect 0 ms 468 KB Output isn't correct
40 Execution timed out 1090 ms 19784 KB Time limit exceeded
41 Incorrect 0 ms 468 KB Output isn't correct
42 Incorrect 2 ms 1236 KB Output isn't correct
43 Execution timed out 1095 ms 76516 KB Time limit exceeded
44 Incorrect 12 ms 6604 KB Output isn't correct
45 Execution timed out 1096 ms 76588 KB Time limit exceeded
46 Execution timed out 1094 ms 76600 KB Time limit exceeded
47 Execution timed out 1087 ms 76572 KB Time limit exceeded
48 Execution timed out 1089 ms 76560 KB Time limit exceeded
49 Execution timed out 1083 ms 76532 KB Time limit exceeded
50 Execution timed out 1095 ms 76600 KB Time limit exceeded
51 Execution timed out 1095 ms 76572 KB Time limit exceeded
52 Execution timed out 1087 ms 76588 KB Time limit exceeded
53 Execution timed out 1082 ms 76512 KB Time limit exceeded
54 Execution timed out 1096 ms 76564 KB Time limit exceeded
55 Execution timed out 1095 ms 76576 KB Time limit exceeded
56 Execution timed out 1093 ms 76552 KB Time limit exceeded
57 Execution timed out 1094 ms 76620 KB Time limit exceeded
58 Execution timed out 1050 ms 76652 KB Time limit exceeded
59 Execution timed out 1097 ms 76564 KB Time limit exceeded
60 Execution timed out 1103 ms 76612 KB Time limit exceeded
61 Execution timed out 1085 ms 76620 KB Time limit exceeded
62 Execution timed out 1097 ms 76568 KB Time limit exceeded
63 Execution timed out 1103 ms 76548 KB Time limit exceeded
64 Execution timed out 1090 ms 76532 KB Time limit exceeded
65 Execution timed out 1091 ms 76556 KB Time limit exceeded
66 Execution timed out 1095 ms 76548 KB Time limit exceeded
67 Execution timed out 1103 ms 76528 KB Time limit exceeded
68 Execution timed out 1094 ms 76620 KB Time limit exceeded
69 Execution timed out 1080 ms 76572 KB Time limit exceeded
70 Execution timed out 1090 ms 61280 KB Time limit exceeded
71 Execution timed out 1081 ms 76616 KB Time limit exceeded
72 Execution timed out 1098 ms 76524 KB Time limit exceeded
73 Execution timed out 1096 ms 76512 KB Time limit exceeded
74 Execution timed out 1090 ms 76544 KB Time limit exceeded
75 Execution timed out 1089 ms 76584 KB Time limit exceeded
76 Execution timed out 1092 ms 76616 KB Time limit exceeded
77 Execution timed out 1088 ms 76572 KB Time limit exceeded
78 Execution timed out 1084 ms 76668 KB Time limit exceeded
79 Execution timed out 1086 ms 76608 KB Time limit exceeded
80 Execution timed out 1093 ms 76600 KB Time limit exceeded
81 Execution timed out 1059 ms 76592 KB Time limit exceeded
82 Execution timed out 1072 ms 76608 KB Time limit exceeded
83 Execution timed out 1095 ms 76520 KB Time limit exceeded
84 Execution timed out 1097 ms 76628 KB Time limit exceeded
85 Execution timed out 1097 ms 76620 KB Time limit exceeded
86 Execution timed out 1092 ms 76524 KB Time limit exceeded
87 Execution timed out 1096 ms 76620 KB Time limit exceeded
88 Execution timed out 1074 ms 76660 KB Time limit exceeded
89 Execution timed out 1095 ms 76620 KB Time limit exceeded
90 Execution timed out 1086 ms 61260 KB Time limit exceeded
91 Execution timed out 1096 ms 76520 KB Time limit exceeded
92 Execution timed out 1085 ms 76616 KB Time limit exceeded
93 Execution timed out 1102 ms 76576 KB Time limit exceeded
94 Execution timed out 1092 ms 76556 KB Time limit exceeded
95 Execution timed out 1091 ms 76620 KB Time limit exceeded
96 Execution timed out 1087 ms 76536 KB Time limit exceeded
97 Execution timed out 1103 ms 76620 KB Time limit exceeded
98 Execution timed out 1089 ms 76584 KB Time limit exceeded
99 Execution timed out 1101 ms 76528 KB Time limit exceeded
100 Execution timed out 1090 ms 76592 KB Time limit exceeded