답안 #505940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
505940 2022-01-11T10:49:47 Z pragmatist Bomb (IZhO17_bomb) C++17
21 / 100
1000 ms 108524 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];
int used[2501][2501], w[2501][2501];

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

void upd(int x1, int y1, int x2, int y2) {
	used[x1][y1]++;
	used[x1][y2+1]--;
	used[x2+1][y1]--;
	used[x2+1][y2+1]++;
}

void solve() {           
	cin >> n >> m;
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			cin >> c[i][j];
			w[i][j] = w[i-1][j] + w[i][j-1] - w[i-1][j-1] + (c[i][j] == '1');
		}
	}
	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;
	int l = 1, r = n;
	while(l <= r) {
		int e = (l + r) >> 1;
		int L = 1, R = m;
		bool cur = 0;
		while(L <= R) {
		    int f = (L + R) >> 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 <= m; ++j) {
			        if(i + e - 1 > n || j + f - 1 > m) break;
					int x = get(i, j, i + e - 1, j + f - 1);
					if(x == e * f) {
						upd(i, j, i + e - 1, j + f - 1);					
					}					
				}
			}
	        for(int i = 1; i <= n; ++i) {
	        	for(int j = 1; j <= m; ++j) {
	        		used[i][j] += used[i-1][j] + used[i][j-1] - used[i-1][j-1];
	        	}
	        }
	        bool ok = 1;
			for(int i = 1; i <= n && ok; ++i) {
				for(int j = 1; j <= m && ok; ++j) {
					if(c[i][j] == '1') ok &= (used[i][j] > 0);
				}
			}
			if(ok) {
				cur = 1;
				ans = max(ans, e * f);
				L = f + 1;
			} else
				R = f - 1;
		}
		if(cur)
			l = e + 1;
		else
			r = e - 1;
	}   
	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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 9 ms 16460 KB Output is correct
4 Correct 8 ms 16460 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Incorrect 1 ms 460 KB Output isn't correct
10 Correct 1 ms 460 KB Output is correct
11 Incorrect 1 ms 460 KB Output isn't correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 452 KB Output is correct
15 Incorrect 1 ms 448 KB Output isn't correct
16 Correct 0 ms 460 KB Output is correct
17 Correct 2 ms 1108 KB Output is correct
18 Incorrect 2 ms 1100 KB Output isn't correct
19 Incorrect 2 ms 1356 KB Output isn't correct
20 Incorrect 3 ms 1348 KB Output isn't correct
21 Correct 2 ms 972 KB Output is correct
22 Correct 2 ms 1228 KB Output is correct
23 Incorrect 4 ms 1480 KB Output isn't correct
24 Incorrect 2 ms 1228 KB Output isn't correct
25 Incorrect 3 ms 1484 KB Output isn't correct
26 Correct 3 ms 1484 KB Output is correct
27 Correct 32 ms 4804 KB Output is correct
28 Correct 41 ms 5196 KB Output is correct
29 Incorrect 52 ms 6468 KB Output isn't correct
30 Incorrect 69 ms 7896 KB Output isn't correct
31 Incorrect 56 ms 6268 KB Output isn't correct
32 Incorrect 58 ms 7116 KB Output isn't correct
33 Incorrect 68 ms 8388 KB Output isn't correct
34 Incorrect 27 ms 5448 KB Output isn't correct
35 Incorrect 75 ms 8396 KB Output isn't correct
36 Correct 115 ms 8416 KB Output is correct
37 Incorrect 1 ms 460 KB Output isn't correct
38 Execution timed out 1048 ms 107860 KB Time limit exceeded
39 Incorrect 1 ms 440 KB Output isn't correct
40 Incorrect 421 ms 22208 KB Output isn't correct
41 Correct 1 ms 460 KB Output is correct
42 Incorrect 3 ms 1476 KB Output isn't correct
43 Execution timed out 1018 ms 107816 KB Time limit exceeded
44 Incorrect 79 ms 8388 KB Output isn't correct
45 Execution timed out 1038 ms 107792 KB Time limit exceeded
46 Execution timed out 1075 ms 107844 KB Time limit exceeded
47 Execution timed out 1010 ms 107760 KB Time limit exceeded
48 Execution timed out 1101 ms 107848 KB Time limit exceeded
49 Execution timed out 1041 ms 107776 KB Time limit exceeded
50 Execution timed out 1038 ms 107800 KB Time limit exceeded
51 Execution timed out 1089 ms 107940 KB Time limit exceeded
52 Execution timed out 1038 ms 107768 KB Time limit exceeded
53 Execution timed out 1012 ms 107812 KB Time limit exceeded
54 Execution timed out 1103 ms 107776 KB Time limit exceeded
55 Execution timed out 1071 ms 107844 KB Time limit exceeded
56 Execution timed out 1022 ms 107772 KB Time limit exceeded
57 Execution timed out 1064 ms 107808 KB Time limit exceeded
58 Execution timed out 1084 ms 107868 KB Time limit exceeded
59 Execution timed out 1029 ms 107864 KB Time limit exceeded
60 Execution timed out 1022 ms 107900 KB Time limit exceeded
61 Execution timed out 1054 ms 107912 KB Time limit exceeded
62 Execution timed out 1048 ms 107904 KB Time limit exceeded
63 Execution timed out 1080 ms 107932 KB Time limit exceeded
64 Execution timed out 1097 ms 107900 KB Time limit exceeded
65 Execution timed out 1058 ms 108024 KB Time limit exceeded
66 Execution timed out 1087 ms 107932 KB Time limit exceeded
67 Execution timed out 1102 ms 107928 KB Time limit exceeded
68 Execution timed out 1103 ms 107968 KB Time limit exceeded
69 Execution timed out 1055 ms 108032 KB Time limit exceeded
70 Execution timed out 1043 ms 87116 KB Time limit exceeded
71 Execution timed out 1016 ms 107960 KB Time limit exceeded
72 Execution timed out 1107 ms 108044 KB Time limit exceeded
73 Execution timed out 1099 ms 108000 KB Time limit exceeded
74 Execution timed out 1076 ms 108024 KB Time limit exceeded
75 Execution timed out 1059 ms 107956 KB Time limit exceeded
76 Execution timed out 1106 ms 107988 KB Time limit exceeded
77 Execution timed out 1062 ms 108100 KB Time limit exceeded
78 Execution timed out 1046 ms 108096 KB Time limit exceeded
79 Execution timed out 1052 ms 108100 KB Time limit exceeded
80 Execution timed out 1109 ms 108108 KB Time limit exceeded
81 Execution timed out 1066 ms 108048 KB Time limit exceeded
82 Execution timed out 1085 ms 108200 KB Time limit exceeded
83 Execution timed out 1088 ms 108160 KB Time limit exceeded
84 Execution timed out 1016 ms 108120 KB Time limit exceeded
85 Execution timed out 1079 ms 108120 KB Time limit exceeded
86 Execution timed out 1038 ms 108156 KB Time limit exceeded
87 Execution timed out 1106 ms 108352 KB Time limit exceeded
88 Execution timed out 1088 ms 108228 KB Time limit exceeded
89 Execution timed out 1044 ms 108196 KB Time limit exceeded
90 Execution timed out 1072 ms 87352 KB Time limit exceeded
91 Execution timed out 1049 ms 108188 KB Time limit exceeded
92 Execution timed out 1054 ms 108256 KB Time limit exceeded
93 Execution timed out 1050 ms 108356 KB Time limit exceeded
94 Execution timed out 1098 ms 108376 KB Time limit exceeded
95 Execution timed out 1012 ms 108336 KB Time limit exceeded
96 Execution timed out 1012 ms 108356 KB Time limit exceeded
97 Execution timed out 1096 ms 108268 KB Time limit exceeded
98 Execution timed out 1058 ms 108344 KB Time limit exceeded
99 Execution timed out 1028 ms 108524 KB Time limit exceeded
100 Execution timed out 1053 ms 108512 KB Time limit exceeded