Submission #505457

# Submission time Handle Problem Language Result Execution time Memory
505457 2022-01-11T05:11:21 Z pragmatist Bomb (IZhO17_bomb) C++17
28 / 100
1000 ms 12612 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;
	}
	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 0 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 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 Correct 41 ms 624 KB Output is correct
18 Correct 30 ms 588 KB Output is correct
19 Correct 165 ms 716 KB Output is correct
20 Correct 160 ms 756 KB Output is correct
21 Correct 11 ms 580 KB Output is correct
22 Correct 44 ms 688 KB Output is correct
23 Correct 626 ms 804 KB Output is correct
24 Correct 118 ms 696 KB Output is correct
25 Correct 939 ms 800 KB Output is correct
26 Execution timed out 1085 ms 716 KB Time limit exceeded
27 Execution timed out 1091 ms 1740 KB Time limit exceeded
28 Execution timed out 1085 ms 1740 KB Time limit exceeded
29 Execution timed out 1087 ms 2124 KB Time limit exceeded
30 Execution timed out 1095 ms 2380 KB Time limit exceeded
31 Execution timed out 1089 ms 1868 KB Time limit exceeded
32 Execution timed out 1080 ms 2224 KB Time limit exceeded
33 Execution timed out 1079 ms 2508 KB Time limit exceeded
34 Execution timed out 1084 ms 1996 KB Time limit exceeded
35 Execution timed out 1081 ms 2508 KB Time limit exceeded
36 Execution timed out 1083 ms 2508 KB Time limit exceeded
37 Correct 1 ms 332 KB Output is correct
38 Execution timed out 1092 ms 12472 KB Time limit exceeded
39 Correct 1 ms 332 KB Output is correct
40 Execution timed out 1090 ms 4488 KB Time limit exceeded
41 Correct 2 ms 332 KB Output is correct
42 Execution timed out 1075 ms 716 KB Time limit exceeded
43 Execution timed out 1090 ms 12444 KB Time limit exceeded
44 Execution timed out 1088 ms 2508 KB Time limit exceeded
45 Execution timed out 1088 ms 12484 KB Time limit exceeded
46 Execution timed out 1049 ms 12484 KB Time limit exceeded
47 Execution timed out 1095 ms 12416 KB Time limit exceeded
48 Execution timed out 1086 ms 12460 KB Time limit exceeded
49 Execution timed out 1082 ms 12484 KB Time limit exceeded
50 Execution timed out 1095 ms 12496 KB Time limit exceeded
51 Execution timed out 1083 ms 12496 KB Time limit exceeded
52 Execution timed out 1094 ms 12484 KB Time limit exceeded
53 Execution timed out 1070 ms 12484 KB Time limit exceeded
54 Execution timed out 1086 ms 12504 KB Time limit exceeded
55 Execution timed out 1096 ms 12456 KB Time limit exceeded
56 Execution timed out 1083 ms 12452 KB Time limit exceeded
57 Execution timed out 1094 ms 12444 KB Time limit exceeded
58 Execution timed out 1091 ms 12524 KB Time limit exceeded
59 Execution timed out 1092 ms 12484 KB Time limit exceeded
60 Execution timed out 1084 ms 12464 KB Time limit exceeded
61 Execution timed out 1053 ms 12404 KB Time limit exceeded
62 Execution timed out 1081 ms 12468 KB Time limit exceeded
63 Execution timed out 1086 ms 12528 KB Time limit exceeded
64 Execution timed out 1094 ms 12500 KB Time limit exceeded
65 Execution timed out 1084 ms 12432 KB Time limit exceeded
66 Execution timed out 1051 ms 12608 KB Time limit exceeded
67 Execution timed out 1091 ms 12496 KB Time limit exceeded
68 Execution timed out 1093 ms 12484 KB Time limit exceeded
69 Execution timed out 1090 ms 12476 KB Time limit exceeded
70 Execution timed out 1091 ms 9992 KB Time limit exceeded
71 Execution timed out 1088 ms 12516 KB Time limit exceeded
72 Execution timed out 1093 ms 12504 KB Time limit exceeded
73 Execution timed out 1083 ms 12484 KB Time limit exceeded
74 Execution timed out 1085 ms 12484 KB Time limit exceeded
75 Execution timed out 1093 ms 12484 KB Time limit exceeded
76 Execution timed out 1080 ms 12484 KB Time limit exceeded
77 Execution timed out 1089 ms 12480 KB Time limit exceeded
78 Execution timed out 1094 ms 12480 KB Time limit exceeded
79 Execution timed out 1096 ms 12420 KB Time limit exceeded
80 Execution timed out 1089 ms 12444 KB Time limit exceeded
81 Execution timed out 1094 ms 12504 KB Time limit exceeded
82 Execution timed out 1076 ms 12500 KB Time limit exceeded
83 Execution timed out 1079 ms 12444 KB Time limit exceeded
84 Execution timed out 1092 ms 12424 KB Time limit exceeded
85 Execution timed out 1092 ms 12424 KB Time limit exceeded
86 Execution timed out 1092 ms 12456 KB Time limit exceeded
87 Execution timed out 1077 ms 12484 KB Time limit exceeded
88 Execution timed out 1082 ms 12504 KB Time limit exceeded
89 Execution timed out 1082 ms 12424 KB Time limit exceeded
90 Execution timed out 1078 ms 9972 KB Time limit exceeded
91 Execution timed out 1080 ms 12524 KB Time limit exceeded
92 Execution timed out 1087 ms 12612 KB Time limit exceeded
93 Execution timed out 1087 ms 12512 KB Time limit exceeded
94 Execution timed out 1083 ms 12488 KB Time limit exceeded
95 Execution timed out 1091 ms 12428 KB Time limit exceeded
96 Execution timed out 1052 ms 12484 KB Time limit exceeded
97 Execution timed out 1083 ms 12536 KB Time limit exceeded
98 Execution timed out 1085 ms 12448 KB Time limit exceeded
99 Execution timed out 1097 ms 12456 KB Time limit exceeded
100 Execution timed out 1099 ms 12504 KB Time limit exceeded