Submission #505455

# Submission time Handle Problem Language Result Execution time Memory
505455 2022-01-11T05:10:24 Z pragmatist Bomb (IZhO17_bomb) C++17
19 / 100
99 ms 6468 KB
#include <bits/stdc++.h>                            
 
#define pb push_back
#define sz(v) (int)v.size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define x first
#define y second
#define int long long
#define nl "\n"
 
using namespace std;

typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair <ll, ll> pii;

const int N = (int)1e6 + 7;
const int M = (int)5e6 + 7;
const ll MOD = (ll)1e9 + 7;                    
const int inf = (int)1e9 + 7;
const ll INF = (ll)3e18 + 7;

pii dir[] = {{-1, -1}, {1, 1}, {-1, 1}, {1, -1}};

int n, m;
char c[2501][2501];
bool used[2501][2501];

void solve() {           
	cin >> n >> m;
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			cin >> c[i][j];
		}
	}
	int ans = inf;
	if(n == 1) {
		int cur = 0;
		for(int i = 1; i <= m; ++i) {
			if(c[1][i] == '1') cur++;
			else {
				if(cur > 0) ans = min(ans, cur);
				cur = 0;
			}
		}
		if(c[1][m] == '1') ans = min(ans, cur);
		cout << ans << nl;		
		return;
	}
	if(m == 1) {
		int cur = 0;
		for(int i = 1; i <= n; ++i) {
			if(c[i][1] == '1') cur++;
			else {
				if(cur > 0) ans = min(ans, cur);
				cur = 0;
			}
		}                                      		
		if(c[n][1] == '1') ans = min(ans, cur);
		cout << ans << nl;		
		return;
	}
	if(n > 50 || m > 50) return;
	ans = 0;
	for(int e = 1; e <= n; ++e) {
		for(int f = 1; f <= n; ++f) {
			bool ok = 1;
			for(int i = 1; i <= n; ++i) fill(used[i] + 1, used[i] + 1 + m, 0);
			for(int i = 1; i <= n; ++i) {
				for(int j = 1; j <= n; ++j) {
			        if(i + e - 1 > n || j + f - 1 > m) continue;
					if(c[i][j] == '1') {
						bool cur = 1;
						for(int ii = i; ii <= i + e - 1 && cur; ++ii) {
							for(int jj = j; jj <= j + f - 1 && cur; ++jj) {
								cur &= (c[ii][jj] == '1');
							}
						}
						if(cur) {
							for(int ii = i; ii <= i + e - 1 && cur; ++ii) {
								for(int jj = j; jj <= j + f - 1 && cur; ++jj) {
									used[ii][jj] = 1;
								}
							}	
						}					
					}
				}
			}
			for(int i = 1; i <= n && ok; ++i) {
				for(int j = 1; j <= n && ok; ++j) {
					if(c[i][j] == '1') ok &= (used[i][j] == 1);
				}
			}
			if(ok) {
				ans = max(ans, e * f);
				//cout << e << ' ' << f << nl;
			}
		}
	}
	cout << ans << nl;
}
                
signed main() {                   
	ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
   	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; ++i) {
        //cout << "Case " << i << ": ";
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 3 ms 6348 KB Output is correct
4 Correct 3 ms 6348 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 248 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 404 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 420 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Incorrect 0 ms 460 KB Output isn't correct
18 Incorrect 1 ms 460 KB Output isn't correct
19 Incorrect 0 ms 460 KB Output isn't correct
20 Incorrect 1 ms 460 KB Output isn't correct
21 Incorrect 0 ms 332 KB Output isn't correct
22 Incorrect 0 ms 460 KB Output isn't correct
23 Incorrect 1 ms 460 KB Output isn't correct
24 Incorrect 0 ms 460 KB Output isn't correct
25 Incorrect 1 ms 460 KB Output isn't correct
26 Incorrect 1 ms 460 KB Output isn't correct
27 Incorrect 1 ms 972 KB Output isn't correct
28 Incorrect 2 ms 972 KB Output isn't correct
29 Incorrect 4 ms 1228 KB Output isn't correct
30 Incorrect 3 ms 1356 KB Output isn't correct
31 Incorrect 2 ms 1100 KB Output isn't correct
32 Incorrect 3 ms 1228 KB Output isn't correct
33 Incorrect 3 ms 1328 KB Output isn't correct
34 Incorrect 2 ms 1100 KB Output isn't correct
35 Incorrect 4 ms 1316 KB Output isn't correct
36 Incorrect 5 ms 1356 KB Output isn't correct
37 Correct 1 ms 332 KB Output is correct
38 Incorrect 94 ms 6416 KB Output isn't correct
39 Correct 1 ms 332 KB Output is correct
40 Incorrect 11 ms 2380 KB Output isn't correct
41 Correct 1 ms 332 KB Output is correct
42 Incorrect 1 ms 460 KB Output isn't correct
43 Incorrect 78 ms 6388 KB Output isn't correct
44 Incorrect 3 ms 1356 KB Output isn't correct
45 Incorrect 77 ms 6296 KB Output isn't correct
46 Incorrect 79 ms 6336 KB Output isn't correct
47 Incorrect 84 ms 6380 KB Output isn't correct
48 Incorrect 79 ms 6400 KB Output isn't correct
49 Incorrect 77 ms 6340 KB Output isn't correct
50 Incorrect 75 ms 6424 KB Output isn't correct
51 Incorrect 75 ms 6408 KB Output isn't correct
52 Incorrect 78 ms 6408 KB Output isn't correct
53 Incorrect 77 ms 6380 KB Output isn't correct
54 Incorrect 76 ms 6340 KB Output isn't correct
55 Incorrect 78 ms 6412 KB Output isn't correct
56 Incorrect 80 ms 6324 KB Output isn't correct
57 Incorrect 77 ms 6340 KB Output isn't correct
58 Incorrect 77 ms 6340 KB Output isn't correct
59 Incorrect 78 ms 6336 KB Output isn't correct
60 Incorrect 78 ms 6340 KB Output isn't correct
61 Incorrect 77 ms 6336 KB Output isn't correct
62 Incorrect 86 ms 6356 KB Output isn't correct
63 Incorrect 77 ms 6360 KB Output isn't correct
64 Incorrect 76 ms 6468 KB Output isn't correct
65 Incorrect 75 ms 6376 KB Output isn't correct
66 Incorrect 81 ms 6364 KB Output isn't correct
67 Incorrect 80 ms 6320 KB Output isn't correct
68 Incorrect 81 ms 6320 KB Output isn't correct
69 Incorrect 75 ms 6372 KB Output isn't correct
70 Incorrect 49 ms 5188 KB Output isn't correct
71 Incorrect 76 ms 6328 KB Output isn't correct
72 Incorrect 78 ms 6352 KB Output isn't correct
73 Incorrect 75 ms 6340 KB Output isn't correct
74 Incorrect 76 ms 6400 KB Output isn't correct
75 Incorrect 75 ms 6372 KB Output isn't correct
76 Incorrect 77 ms 6344 KB Output isn't correct
77 Incorrect 79 ms 6316 KB Output isn't correct
78 Incorrect 76 ms 6392 KB Output isn't correct
79 Incorrect 80 ms 6368 KB Output isn't correct
80 Incorrect 76 ms 6340 KB Output isn't correct
81 Incorrect 75 ms 6340 KB Output isn't correct
82 Incorrect 87 ms 6376 KB Output isn't correct
83 Incorrect 75 ms 6328 KB Output isn't correct
84 Incorrect 75 ms 6356 KB Output isn't correct
85 Incorrect 75 ms 6308 KB Output isn't correct
86 Incorrect 77 ms 6388 KB Output isn't correct
87 Incorrect 76 ms 6292 KB Output isn't correct
88 Incorrect 77 ms 6348 KB Output isn't correct
89 Incorrect 82 ms 6468 KB Output isn't correct
90 Incorrect 48 ms 5188 KB Output isn't correct
91 Incorrect 75 ms 6360 KB Output isn't correct
92 Incorrect 76 ms 6392 KB Output isn't correct
93 Incorrect 79 ms 6360 KB Output isn't correct
94 Incorrect 76 ms 6340 KB Output isn't correct
95 Incorrect 76 ms 6384 KB Output isn't correct
96 Incorrect 75 ms 6396 KB Output isn't correct
97 Incorrect 75 ms 6308 KB Output isn't correct
98 Incorrect 76 ms 6348 KB Output isn't correct
99 Incorrect 77 ms 6360 KB Output isn't correct
100 Incorrect 99 ms 6348 KB Output isn't correct