Submission #35060

# Submission time Handle Problem Language Result Execution time Memory
35060 2017-11-17T20:42:00 Z model_code Bomb (IZhO17_bomb) C++14
29 / 100
1000 ms 103624 KB
#include<bits/stdc++.h>

using namespace std;

const int N = 2550;

int ans;
int n, m, a[N][N];
int s[N][N], H, W;
int f[N][N], bad[N][N];
char S[N];

inline void press(int i, int j, int h, int w)
{
	bad[i][j]++;
	bad[i + h][j + w]++;
	bad[i + h][j]--;
	bad[i][j + w]--;
}

inline bool can(int h, int w)
{
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			bad[i][j] = 0, f[i][j] = 0;
	for(int i = 1; i + h - 1 <= n; ++i)
		for(int j = 1; j + w - 1 <= m; ++j)
			if(s[i + h - 1][j + w - 1] - s[i + h - 1][j - 1] - s[i - 1][j + w - 1] + s[i - 1][j - 1] == h * w)
				press(i, j, h, w);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
		{
			f[i][j] = f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1] + bad[i][j];
			if(a[i][j] == 1 && f[i][j] <= 0) 
				return false;
		}
	return true;
}

inline int getw(int h)
{
	int L = 0, R = W + 1;
	while(L + 1 < R)
	{
		int w = (L + R) >> 1;
		if(can(h, w))
			L = w;
		else
			R = w;
	}
	return L;
}

inline int geth(int w)
{
	int L = 0, R = H + 1;
	while(L + 1 < R)
	{
		int h = (L + R) >> 1;
		if(can(h, w))
			L = h;
		else
			R = h;
	}
	return L;
}

int main()
{
	scanf("%d%d", &n, &m);

	for(int i = 2; i <= n + 1; ++i)
	{
		scanf("%s\n", S);
		for(int j = 2; j <= m + 1; ++j)
			a[i][j] = S[j - 2] - '0';
	}
	
	n += 2, m += 2;

	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
	
	H = n, W = m;

	for(int i = 1; i <= n; ++i)
	{
		int cnt = 0;
		for(int j = 1; j <= m; ++j)
			if(a[i][j] == 1) cnt++;
			else 
			{
				if(cnt) W = min(W, cnt);
				cnt = 0;
			}
	}

	for(int j = 1; j <= m; ++j)
	{
		int cnt = 0;
		for(int i = 1; i <= n; ++i)
			if(a[i][j] == 1) cnt++;
			else
			{
				if(cnt) H = min(H, cnt);
				cnt = 0;
			}
	}

	int L = 1, R = H + 1;
	while(L + 2 < R)
	{
		int ma = L + R >> 1;
		if(getw(ma) * ma < getw(ma + 1) * (ma + 1))
			L = ma;
		else
			R = ma + 1;
	}

	for(int i = L; i <= R; ++i)
		ans = max(ans, getw(i) * i);

	L = 1, R = W + 1;
	while(L + 2 < R)
	{
		int ma = L + R >> 1;
		if(geth(ma) * ma < geth(ma + 1) * (ma + 1))
			L = ma;
		else
			R = ma + 1;
	}

	for(int i = L; i <= R; ++i)
		ans = max(ans, geth(i) * i);

	printf("%d\n", ans);
		
	return 0;
}

Compilation message

bomb.cpp: In function 'int main()':
bomb.cpp:114:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int ma = L + R >> 1;
              ^
bomb.cpp:127:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int ma = L + R >> 1;
              ^
bomb.cpp:70:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
                       ^
bomb.cpp:74:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s\n", S);
                   ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 103624 KB Output is correct
2 Correct 0 ms 103624 KB Output is correct
3 Correct 13 ms 103624 KB Output is correct
4 Correct 9 ms 103624 KB Output is correct
5 Correct 0 ms 103624 KB Output is correct
6 Correct 0 ms 103624 KB Output is correct
7 Correct 0 ms 103624 KB Output is correct
8 Correct 0 ms 103624 KB Output is correct
9 Correct 0 ms 103624 KB Output is correct
10 Correct 0 ms 103624 KB Output is correct
11 Correct 0 ms 103624 KB Output is correct
12 Correct 0 ms 103624 KB Output is correct
13 Correct 0 ms 103624 KB Output is correct
14 Correct 0 ms 103624 KB Output is correct
15 Correct 0 ms 103624 KB Output is correct
16 Correct 0 ms 103624 KB Output is correct
17 Correct 0 ms 103624 KB Output is correct
18 Correct 0 ms 103624 KB Output is correct
19 Incorrect 3 ms 103624 KB Output isn't correct
20 Correct 3 ms 103624 KB Output is correct
21 Correct 0 ms 103624 KB Output is correct
22 Correct 0 ms 103624 KB Output is correct
23 Incorrect 6 ms 103624 KB Output isn't correct
24 Incorrect 3 ms 103624 KB Output isn't correct
25 Incorrect 6 ms 103624 KB Output isn't correct
26 Correct 6 ms 103624 KB Output is correct
27 Correct 6 ms 103624 KB Output is correct
28 Correct 36 ms 103624 KB Output is correct
29 Correct 193 ms 103624 KB Output is correct
30 Incorrect 209 ms 103624 KB Output isn't correct
31 Incorrect 139 ms 103624 KB Output isn't correct
32 Incorrect 149 ms 103624 KB Output isn't correct
33 Incorrect 263 ms 103624 KB Output isn't correct
34 Correct 43 ms 103624 KB Output is correct
35 Incorrect 136 ms 103624 KB Output isn't correct
36 Correct 236 ms 103624 KB Output is correct
37 Incorrect 0 ms 103624 KB Output isn't correct
38 Execution timed out 1000 ms 103624 KB Execution timed out
39 Correct 0 ms 103624 KB Output is correct
40 Execution timed out 1000 ms 103624 KB Execution timed out
41 Correct 0 ms 103624 KB Output is correct
42 Incorrect 9 ms 103624 KB Output isn't correct
43 Execution timed out 1000 ms 103624 KB Execution timed out
44 Incorrect 343 ms 103624 KB Output isn't correct
45 Execution timed out 1000 ms 103624 KB Execution timed out
46 Execution timed out 1000 ms 103624 KB Execution timed out
47 Execution timed out 1000 ms 103624 KB Execution timed out
48 Execution timed out 1000 ms 103624 KB Execution timed out
49 Execution timed out 1000 ms 103624 KB Execution timed out
50 Execution timed out 1000 ms 103624 KB Execution timed out
51 Execution timed out 1000 ms 103624 KB Execution timed out
52 Execution timed out 1000 ms 103624 KB Execution timed out
53 Execution timed out 1000 ms 103624 KB Execution timed out
54 Execution timed out 1000 ms 103624 KB Execution timed out
55 Execution timed out 1000 ms 103624 KB Execution timed out
56 Execution timed out 1000 ms 103624 KB Execution timed out
57 Execution timed out 1000 ms 103624 KB Execution timed out
58 Execution timed out 1000 ms 103624 KB Execution timed out
59 Execution timed out 1000 ms 103624 KB Execution timed out
60 Execution timed out 1000 ms 103624 KB Execution timed out
61 Execution timed out 1000 ms 103624 KB Execution timed out
62 Execution timed out 1000 ms 103624 KB Execution timed out
63 Execution timed out 1000 ms 103624 KB Execution timed out
64 Execution timed out 1000 ms 103624 KB Execution timed out
65 Execution timed out 1000 ms 103624 KB Execution timed out
66 Execution timed out 1000 ms 103624 KB Execution timed out
67 Execution timed out 1000 ms 103624 KB Execution timed out
68 Execution timed out 1000 ms 103624 KB Execution timed out
69 Execution timed out 1000 ms 103624 KB Execution timed out
70 Execution timed out 1000 ms 103624 KB Execution timed out
71 Execution timed out 1000 ms 103624 KB Execution timed out
72 Execution timed out 1000 ms 103624 KB Execution timed out
73 Execution timed out 1000 ms 103624 KB Execution timed out
74 Execution timed out 1000 ms 103624 KB Execution timed out
75 Execution timed out 1000 ms 103624 KB Execution timed out
76 Execution timed out 1000 ms 103624 KB Execution timed out
77 Execution timed out 1000 ms 103624 KB Execution timed out
78 Execution timed out 1000 ms 103624 KB Execution timed out
79 Execution timed out 1000 ms 103624 KB Execution timed out
80 Execution timed out 1000 ms 103624 KB Execution timed out
81 Execution timed out 1000 ms 103624 KB Execution timed out
82 Execution timed out 1000 ms 103624 KB Execution timed out
83 Execution timed out 1000 ms 103624 KB Execution timed out
84 Execution timed out 1000 ms 103624 KB Execution timed out
85 Execution timed out 1000 ms 103624 KB Execution timed out
86 Execution timed out 1000 ms 103624 KB Execution timed out
87 Execution timed out 1000 ms 103624 KB Execution timed out
88 Execution timed out 1000 ms 103624 KB Execution timed out
89 Execution timed out 1000 ms 103624 KB Execution timed out
90 Execution timed out 1000 ms 103624 KB Execution timed out
91 Execution timed out 1000 ms 103624 KB Execution timed out
92 Execution timed out 1000 ms 103624 KB Execution timed out
93 Execution timed out 1000 ms 103624 KB Execution timed out
94 Execution timed out 1000 ms 103624 KB Execution timed out
95 Execution timed out 1000 ms 103624 KB Execution timed out
96 Execution timed out 1000 ms 103624 KB Execution timed out
97 Execution timed out 1000 ms 103624 KB Execution timed out
98 Execution timed out 1000 ms 103624 KB Execution timed out
99 Execution timed out 1000 ms 103624 KB Execution timed out
100 Execution timed out 1000 ms 103624 KB Execution timed out