답안 #686397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
686397 2023-01-25T08:53:38 Z pragmatist Bomb (IZhO17_bomb) C++17
33 / 100
1000 ms 55604 KB
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/

#include<bits/stdc++.h>
 
#define ld long double
#define sz(v) (int)v.size()
#define ll long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define nl "\n"

using namespace std;

const int N = (int)25e2 + 7; // make sure this is right
const int M = (int)1e6 + 7;
const int B = 351;
const int inf = (int)2e9 + 7;
const ll INF = (ll)3e18 + 7; 
const ll MOD = (ll)1e9 + 7; // make sure this is right

bool bit(int x, int i) {
	return x >> i & 1;
}

int mult(int x, int y) {
	return 1ll * x * y % MOD;
}

int sum(int x, int y) {
	x += y;
	if(x >= MOD) x -= MOD;
	return x;
}

int n, m, p[N][N], e[N][N];
char a[N][N];

int get(int x1, int y1, int x2, int y2) {
	return (p[x2][y2] - p[x1 - 1][y2] - p[x2][y1 - 1] + p[x1 - 1][y1 - 1]);
}

void solve() {
	cin >> n >> m;
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			cin >> a[i][j];
			p[i][j] = p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1] + (a[i][j] == '1');
		}
	}
	int ans = 0;                      
	for(int h = 1; h <= n; ++h) {
		int l = 1, r = m;
		while(l <= r) {
    		int w = (l + r) >> 1;
    		for(int i = 1; i <= n -	h + 1; ++i) {
    			for(int j = 1; j <= m - w + 1; ++j) {
					int ii = i + h - 1, jj = j + w - 1;
					int x = get(i, j, ii, jj);
					if(x == h * w) {
						e[i][j]++;
						e[i][jj + 1]--;
						e[ii + 1][j]--;
						e[ii + 1][jj + 1]++;			
    				}	
    			}
    		}
			for(int i = 1; i <= n; ++i) {
				for(int j = 1; j <= m; ++j) {
					e[i][j] += e[i - 1][j];
					e[i][j] += e[i][j - 1];
					e[i][j] -= e[i - 1][j - 1];
				}
			}

			bool ok = 1;
			for(int i = 1; i <= n && ok; ++i) {
				for(int j = 1; j <= m && ok; ++j) {
					if(a[i][j] == '1') {
						ok &= (e[i][j] > 0);
					}
				}
			}
			for(int i = 1; i <= n; ++i) {
				for(int j = 1; j <= m; ++j) {
					e[i][j] = 0;
				}
			}
			if(ok) {
				ans = max(ans, h * w);
				l = w + 1;
			} else
				r = w - 1;
    	}
	}
	cout << ans << "\n";
}
	
signed main() {	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int test = 1;
	//cin >> test;
	for(int i = 1; i <= test; ++i) {
	 	//cout << "Case #" << i << ": ";
		solve();
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 171 ms 26572 KB Output is correct
4 Correct 149 ms 26536 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 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 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 420 KB Output is correct
14 Correct 0 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 7 ms 980 KB Output is correct
18 Correct 7 ms 1036 KB Output is correct
19 Correct 17 ms 1400 KB Output is correct
20 Correct 17 ms 1368 KB Output is correct
21 Correct 6 ms 936 KB Output is correct
22 Correct 12 ms 1108 KB Output is correct
23 Correct 22 ms 1364 KB Output is correct
24 Correct 11 ms 1236 KB Output is correct
25 Correct 24 ms 1464 KB Output is correct
26 Correct 24 ms 1468 KB Output is correct
27 Correct 713 ms 4052 KB Output is correct
28 Correct 909 ms 4224 KB Output is correct
29 Execution timed out 1060 ms 5332 KB Time limit exceeded
30 Execution timed out 1094 ms 6228 KB Time limit exceeded
31 Execution timed out 1057 ms 4948 KB Time limit exceeded
32 Execution timed out 1090 ms 5716 KB Time limit exceeded
33 Execution timed out 1091 ms 6612 KB Time limit exceeded
34 Correct 710 ms 4720 KB Output is correct
35 Execution timed out 1076 ms 6612 KB Time limit exceeded
36 Execution timed out 1097 ms 6612 KB Time limit exceeded
37 Correct 1 ms 468 KB Output is correct
38 Execution timed out 1090 ms 55472 KB Time limit exceeded
39 Correct 1 ms 468 KB Output is correct
40 Execution timed out 1088 ms 15452 KB Time limit exceeded
41 Correct 1 ms 468 KB Output is correct
42 Correct 29 ms 1468 KB Output is correct
43 Execution timed out 1095 ms 55424 KB Time limit exceeded
44 Execution timed out 1089 ms 6652 KB Time limit exceeded
45 Execution timed out 1098 ms 55468 KB Time limit exceeded
46 Execution timed out 1082 ms 55604 KB Time limit exceeded
47 Execution timed out 1071 ms 55508 KB Time limit exceeded
48 Execution timed out 1089 ms 55512 KB Time limit exceeded
49 Execution timed out 1076 ms 55572 KB Time limit exceeded
50 Execution timed out 1098 ms 55400 KB Time limit exceeded
51 Execution timed out 1095 ms 55440 KB Time limit exceeded
52 Execution timed out 1086 ms 55516 KB Time limit exceeded
53 Execution timed out 1096 ms 55508 KB Time limit exceeded
54 Execution timed out 1090 ms 55432 KB Time limit exceeded
55 Execution timed out 1089 ms 55420 KB Time limit exceeded
56 Execution timed out 1097 ms 55504 KB Time limit exceeded
57 Execution timed out 1096 ms 55448 KB Time limit exceeded
58 Execution timed out 1080 ms 55504 KB Time limit exceeded
59 Execution timed out 1092 ms 55500 KB Time limit exceeded
60 Execution timed out 1095 ms 55380 KB Time limit exceeded
61 Execution timed out 1087 ms 55448 KB Time limit exceeded
62 Execution timed out 1086 ms 55420 KB Time limit exceeded
63 Execution timed out 1075 ms 55396 KB Time limit exceeded
64 Execution timed out 1078 ms 55428 KB Time limit exceeded
65 Execution timed out 1078 ms 55520 KB Time limit exceeded
66 Execution timed out 1090 ms 55500 KB Time limit exceeded
67 Execution timed out 1094 ms 55460 KB Time limit exceeded
68 Execution timed out 1093 ms 55412 KB Time limit exceeded
69 Execution timed out 1097 ms 55444 KB Time limit exceeded
70 Execution timed out 1079 ms 44380 KB Time limit exceeded
71 Execution timed out 1095 ms 55500 KB Time limit exceeded
72 Execution timed out 1091 ms 55504 KB Time limit exceeded
73 Execution timed out 1080 ms 55420 KB Time limit exceeded
74 Execution timed out 1046 ms 55400 KB Time limit exceeded
75 Execution timed out 1090 ms 55384 KB Time limit exceeded
76 Execution timed out 1043 ms 55500 KB Time limit exceeded
77 Execution timed out 1089 ms 55412 KB Time limit exceeded
78 Execution timed out 1095 ms 55508 KB Time limit exceeded
79 Execution timed out 1095 ms 55472 KB Time limit exceeded
80 Execution timed out 1091 ms 55436 KB Time limit exceeded
81 Execution timed out 1102 ms 55464 KB Time limit exceeded
82 Execution timed out 1088 ms 55408 KB Time limit exceeded
83 Execution timed out 1077 ms 55500 KB Time limit exceeded
84 Execution timed out 1100 ms 55380 KB Time limit exceeded
85 Execution timed out 1086 ms 55500 KB Time limit exceeded
86 Execution timed out 1094 ms 55396 KB Time limit exceeded
87 Execution timed out 1089 ms 55416 KB Time limit exceeded
88 Execution timed out 1101 ms 55412 KB Time limit exceeded
89 Execution timed out 1098 ms 55448 KB Time limit exceeded
90 Execution timed out 1096 ms 44396 KB Time limit exceeded
91 Execution timed out 1087 ms 55484 KB Time limit exceeded
92 Execution timed out 1099 ms 55404 KB Time limit exceeded
93 Execution timed out 1073 ms 55500 KB Time limit exceeded
94 Execution timed out 1094 ms 55416 KB Time limit exceeded
95 Execution timed out 1089 ms 55460 KB Time limit exceeded
96 Execution timed out 1054 ms 55524 KB Time limit exceeded
97 Execution timed out 1088 ms 55500 KB Time limit exceeded
98 Execution timed out 1087 ms 55504 KB Time limit exceeded
99 Execution timed out 1054 ms 55504 KB Time limit exceeded
100 Execution timed out 1096 ms 55512 KB Time limit exceeded