답안 #391746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
391746 2021-04-19T16:17:32 Z patrikpavic2 Bomb (IZhO17_bomb) C++17
100 / 100
744 ms 96468 KB
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
 
#define PB push_back
 
using namespace std;
 
const int N = 2505;
 
int n, m;
char s[N][N];
int A[N][N], B[N][N];
 
int par[N], L[N], R[N], un[N], nula[N];
int S[N];
 
int pr(int x){
	if(x == par[x]) return x;
	return par[x] = pr(par[x]);
}
 
void mrg(int x, int y){
	if(x < 0 || y >= m || !un[x] || !un[y]) return;
//	printf("mrg %d %d\n", x, y);
	x = pr(x), y = pr(y);
	if(x == y) return;
	if(nula[x]) S[R[x] - L[x] + 1]--; 
	if(nula[y]) S[R[y] - L[y] + 1]--;
	if(R[x] - L[x] > R[y] - L[y]){
		par[y] = x; R[x] = R[y];
		nula[x] |= nula[y];
		if(nula[x])
			S[R[x] - L[x] + 1]++;
	}
	else{
		par[x] = y; L[y] = L[x];
		nula[y] |= nula[x];
		if(nula[y])
			S[R[y] - L[y] + 1]++;
	}
}
 
vector < int > kon[N];
int ans[N];
 
void odradi_redak(int rd){
	for(int i = 0;i <= m;i++) S[i] = 0;
	for(int i = 0;i <= n;i++) kon[i].clear();
	for(int i = 0;i < m;i++){
		un[i] = 0; 
		if(s[rd][i] == '0') continue;
		par[i] = i; nula[i] = (B[rd][i] == 1);
		L[i] = i, R[i] = i;
		kon[A[rd][i]].PB(i);
		if(nula[i]) S[0]++;
	}
	if(!S[0]) return;
	int cur = 0;
	for(int i = n;i >= 1;i--){
		for(int x : kon[i]){
			if(nula[x])
				S[0]--, S[1]++;
		//	printf("x = %d nula = %d\n", x, nula[x]);
			un[x] = 1;
			mrg(x - 1, x);
			mrg(x, x + 1);
		}
		while(!S[cur]) cur++;
		//printf("rd = %d i = %d cur = %d\n", rd, i, cur);
		ans[i] = min(ans[i], cur);
	}
}
 
int main(){
	//freopen("bomb.in", "r", stdin);
	//freopen("bomb.out", "w", stdout);
	scanf("%d%d", &n, &m);
	int fin = 0;
	for(int i = 0;i < n;i++)
		for(int j = 0;j < m;j++)
			scanf(" %c", &s[i][j]);
	for(int i = 1;i <= n;i++) ans[i] = m;
	for(int bla = 0;bla < 2;bla++){
		memset(A, 0, sizeof(A));
		memset(B, 0, sizeof(B));
		for(int i = 0;i < n;i++)
			for(int j = 0;j < m;j++)
				A[i][j] = (1 + (i ? A[i - 1][j] : 0)) * (s[i][j] - '0');
		for(int i = n - 1;i >= 0;i--)
			for(int j = 0;j < m;j++)
				B[i][j] = (1 + B[i + 1][j]) * (s[i][j] - '0');
		int min_j = n, min_i = m;
		for(int i = 0;i < n;i++)
			for(int j = 0;j < m;j++)
				if(s[i][j] == '1') min_j = min(min_j, A[i][j] + B[i][j] - 1);
		for(int i = 0;i < n;i++){
			for(int j = 0;j < m;){
				if(s[i][j] == '0'){
					j++; continue;
				}
				int jj = j;
				while(j < m && s[i][j] == '1') j++;
				min_i = min(min_i, j - jj);
			}
		}
		for(int i = 1;i <= min_j;i++) ans[i] = min(ans[i], min_i);
		for(int i = min_j + 1;i <= n;i++) ans[i] = 0; 
		for(int i = 0;i < n;i++) odradi_redak(i);
		for(int i = 0;n - i - 1 > i;i++){
			for(int j = 0;j < m;j++)
				swap(s[i][j], s[n - i - 1][j]);
		}
	}
	for(int i = 1;i <= n;i++){
		fin = max(fin, ans[i] * i);
	}
	printf("%d\n", fin);
	return 0;
}
 
/*
5 6
000000
111110
111110
111110
001000
 
*/

Compilation message

bomb.cpp: In function 'int main()':
bomb.cpp:79:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   79 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
bomb.cpp:83:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   83 |    scanf(" %c", &s[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 49484 KB Output is correct
2 Correct 30 ms 49424 KB Output is correct
3 Correct 49 ms 55656 KB Output is correct
4 Correct 50 ms 55608 KB Output is correct
5 Correct 32 ms 49452 KB Output is correct
6 Correct 32 ms 49512 KB Output is correct
7 Correct 32 ms 49476 KB Output is correct
8 Correct 35 ms 49416 KB Output is correct
9 Correct 32 ms 49436 KB Output is correct
10 Correct 33 ms 49472 KB Output is correct
11 Correct 34 ms 49488 KB Output is correct
12 Correct 32 ms 49476 KB Output is correct
13 Correct 32 ms 49484 KB Output is correct
14 Correct 33 ms 49516 KB Output is correct
15 Correct 32 ms 49536 KB Output is correct
16 Correct 32 ms 49520 KB Output is correct
17 Correct 34 ms 49748 KB Output is correct
18 Correct 32 ms 49656 KB Output is correct
19 Correct 33 ms 49680 KB Output is correct
20 Correct 33 ms 49736 KB Output is correct
21 Correct 32 ms 49516 KB Output is correct
22 Correct 33 ms 49624 KB Output is correct
23 Correct 34 ms 49736 KB Output is correct
24 Correct 32 ms 49704 KB Output is correct
25 Correct 34 ms 49776 KB Output is correct
26 Correct 37 ms 49812 KB Output is correct
27 Correct 43 ms 50572 KB Output is correct
28 Correct 47 ms 50244 KB Output is correct
29 Correct 47 ms 50664 KB Output is correct
30 Correct 51 ms 50736 KB Output is correct
31 Correct 43 ms 50552 KB Output is correct
32 Correct 46 ms 50668 KB Output is correct
33 Correct 57 ms 50896 KB Output is correct
34 Correct 41 ms 50368 KB Output is correct
35 Correct 51 ms 50696 KB Output is correct
36 Correct 53 ms 51652 KB Output is correct
37 Correct 32 ms 49500 KB Output is correct
38 Correct 654 ms 96468 KB Output is correct
39 Correct 32 ms 49496 KB Output is correct
40 Correct 108 ms 54860 KB Output is correct
41 Correct 32 ms 49452 KB Output is correct
42 Correct 36 ms 49748 KB Output is correct
43 Correct 690 ms 66880 KB Output is correct
44 Correct 52 ms 51152 KB Output is correct
45 Correct 634 ms 76292 KB Output is correct
46 Correct 598 ms 62032 KB Output is correct
47 Correct 634 ms 76500 KB Output is correct
48 Correct 608 ms 72100 KB Output is correct
49 Correct 684 ms 95548 KB Output is correct
50 Correct 596 ms 72988 KB Output is correct
51 Correct 597 ms 72896 KB Output is correct
52 Correct 592 ms 72284 KB Output is correct
53 Correct 611 ms 71888 KB Output is correct
54 Correct 601 ms 71812 KB Output is correct
55 Correct 566 ms 71844 KB Output is correct
56 Correct 634 ms 96004 KB Output is correct
57 Correct 566 ms 72052 KB Output is correct
58 Correct 556 ms 72264 KB Output is correct
59 Correct 554 ms 71876 KB Output is correct
60 Correct 744 ms 79200 KB Output is correct
61 Correct 635 ms 95572 KB Output is correct
62 Correct 634 ms 92136 KB Output is correct
63 Correct 646 ms 96440 KB Output is correct
64 Correct 541 ms 69656 KB Output is correct
65 Correct 589 ms 71876 KB Output is correct
66 Correct 567 ms 72280 KB Output is correct
67 Correct 615 ms 74308 KB Output is correct
68 Correct 621 ms 76868 KB Output is correct
69 Correct 544 ms 72328 KB Output is correct
70 Correct 345 ms 59336 KB Output is correct
71 Correct 516 ms 64352 KB Output is correct
72 Correct 534 ms 65048 KB Output is correct
73 Correct 539 ms 64772 KB Output is correct
74 Correct 546 ms 64688 KB Output is correct
75 Correct 556 ms 66116 KB Output is correct
76 Correct 556 ms 64844 KB Output is correct
77 Correct 559 ms 65808 KB Output is correct
78 Correct 537 ms 65052 KB Output is correct
79 Correct 528 ms 61736 KB Output is correct
80 Correct 526 ms 61800 KB Output is correct
81 Correct 509 ms 62376 KB Output is correct
82 Correct 568 ms 66032 KB Output is correct
83 Correct 547 ms 65204 KB Output is correct
84 Correct 497 ms 61744 KB Output is correct
85 Correct 606 ms 66020 KB Output is correct
86 Correct 611 ms 93064 KB Output is correct
87 Correct 547 ms 67288 KB Output is correct
88 Correct 540 ms 65452 KB Output is correct
89 Correct 567 ms 76164 KB Output is correct
90 Correct 351 ms 60976 KB Output is correct
91 Correct 551 ms 72128 KB Output is correct
92 Correct 586 ms 73412 KB Output is correct
93 Correct 614 ms 92360 KB Output is correct
94 Correct 584 ms 75296 KB Output is correct
95 Correct 561 ms 65332 KB Output is correct
96 Correct 544 ms 65288 KB Output is correct
97 Correct 627 ms 93260 KB Output is correct
98 Correct 543 ms 66752 KB Output is correct
99 Correct 562 ms 74892 KB Output is correct
100 Correct 644 ms 91760 KB Output is correct