Submission #386506

# Submission time Handle Problem Language Result Execution time Memory
386506 2021-04-06T16:49:13 Z vanic Bomb (IZhO17_bomb) C++14
23 / 100
1000 ms 127208 KB
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#include <cstring>
#include <array>
#include <bitset>
#include <cassert>
 
using namespace std;
 
const int maxn=2505;
 
bitset < maxn > a[maxn];
bitset < maxn > bio[maxn];
int dist1[maxn][maxn];
int dist2[maxn][maxn];
int pref[maxn][maxn];
int uk;
int n, m;
 
bool provjeri(int x, int y){
	for(int i=0; i<n; i++){
		bio[i].reset();
	}
	int val;
	queue < pair < int, int > > q;
	int br=0;
	for(int i=0; i<=n-x; i++){
		for(int j=0; j<=m-y; j++){
			val=pref[i+x][j+y]-pref[i][j+y]-pref[i+x][j]+pref[i][j];
			if(val==x*y){
				br++;
				q.push({i, j});
				dist1[i][j]=0;
				dist2[i][j]=0;
				bio[i][j]=1;
			}
		}
	}
	pair < int, int > p;
	int xs, ys;
//	cout << "pocetak " << x << ' ' << y << endl;
	while(!q.empty()){
		p=q.front();
		q.pop();
		xs=p.first+1;
		ys=p.second;
		if(!bio[xs][ys] && dist1[p.first][p.second]+1<x){
			br++;
			bio[xs][ys]=1;
			dist1[xs][ys]=dist1[p.first][p.second]+1;
			dist2[xs][ys]=dist2[p.first][p.second];
			
			q.push({xs, ys});
		}
		xs=p.first;
		ys=p.second+1;
		if(!bio[xs][ys] && dist2[p.first][p.second]+1<y){
			br++;
			bio[xs][ys]=1;
			dist1[xs][ys]=dist1[p.first][p.second];
			dist2[xs][ys]=dist2[p.first][p.second]+1;
			q.push({xs, ys});
		}
	}
//	cout << br << endl;
	return br==uk;
}

int binary(int hi, int val){
	int lo=1, mid;
//	cout << lo << ' ' << hi << endl;
	while(lo<hi){
		mid=(lo+hi)/2+1;
		if(provjeri(val, mid)){
			lo=mid;
		}
		else{
			hi=mid-1;
		}
	}
	return lo;
}

int ternary(int hi, int hi1){
	int lo=1, mid;
//	cout << lo << ' ' << hi << endl;
	while(lo<hi){
		mid=(lo+hi)/2;
//		cout << mid << endl;
		if(binary(hi1, mid)*mid<binary(hi1, mid+1)*(mid+1)){
			lo=mid+1;
		}
		else{
			hi=mid;
		}
	}
	return lo*binary(hi1, lo);
}

vector < array < int, 3 > > svi;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	string s;
	for(int i=0; i<n; i++){
		cin >> s;
		for(int j=0; j<m; j++){
			pref[i+1][j+1]=pref[i][j+1]+pref[i+1][j]-pref[i][j];
			if(s[j]=='1'){
				pref[i+1][j+1]++;
				uk++;
				a[i][j]=1;
			}
		}
	}
	int br=0;
	int mr=1e9, mc=1e9;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(a[i][j]){
				br++;
			}
			else if(br){
				mr=min(mr, br);
				br=0;
			}
		}
		if(br){
			mr=min(mr, br);
			br=0;
		}
	}
	for(int j=0; j<m; j++){
		for(int i=0; i<n; i++){
			if(a[i][j]){
				br++;
			}
			else if(br){
				mc=min(mc, br);
				br=0;
			}
		}
		if(br){
			mc=min(mc, br);
			br=0;
		}
	}
	assert(mr!=1e9);
	for(int i=mc; i>0; i--){
		for(int j=mr; j>0; j--){
			svi.push_back({i*j, i, j});
		}
	}
	sort(svi.begin(), svi.end());
	cout << ternary(mc, mr) << '\n';
/*	for(int i=svi.size()-1; i>-1; i--){
		if(provjeri(svi[i][1], svi[i][2])){
			cout << svi[i][0] << '\n';
			return 0;
		}
	}*/
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 8 ms 11116 KB Output is correct
4 Correct 9 ms 11116 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Incorrect 2 ms 620 KB Output isn't correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Incorrect 1 ms 620 KB Output isn't correct
16 Correct 1 ms 620 KB Output is correct
17 Incorrect 2 ms 1260 KB Output isn't correct
18 Correct 2 ms 1004 KB Output is correct
19 Incorrect 3 ms 1260 KB Output isn't correct
20 Incorrect 3 ms 1260 KB Output isn't correct
21 Correct 1 ms 748 KB Output is correct
22 Correct 2 ms 1004 KB Output is correct
23 Correct 4 ms 1388 KB Output is correct
24 Incorrect 3 ms 1260 KB Output isn't correct
25 Incorrect 6 ms 1644 KB Output isn't correct
26 Correct 6 ms 1772 KB Output is correct
27 Correct 6 ms 5612 KB Output is correct
28 Correct 7 ms 2412 KB Output is correct
29 Incorrect 177 ms 7368 KB Output isn't correct
30 Incorrect 93 ms 6232 KB Output isn't correct
31 Incorrect 54 ms 4656 KB Output isn't correct
32 Incorrect 43 ms 5740 KB Output isn't correct
33 Incorrect 148 ms 7532 KB Output isn't correct
34 Correct 7 ms 2796 KB Output is correct
35 Incorrect 32 ms 3692 KB Output isn't correct
36 Correct 179 ms 10016 KB Output is correct
37 Incorrect 1 ms 620 KB Output isn't correct
38 Execution timed out 1095 ms 124284 KB Time limit exceeded
39 Incorrect 1 ms 620 KB Output isn't correct
40 Execution timed out 1082 ms 24416 KB Time limit exceeded
41 Incorrect 1 ms 620 KB Output isn't correct
42 Incorrect 9 ms 1772 KB Output isn't correct
43 Execution timed out 1096 ms 104904 KB Time limit exceeded
44 Incorrect 259 ms 9064 KB Output isn't correct
45 Execution timed out 1098 ms 110828 KB Time limit exceeded
46 Execution timed out 1094 ms 82028 KB Time limit exceeded
47 Execution timed out 1085 ms 110924 KB Time limit exceeded
48 Execution timed out 1099 ms 103152 KB Time limit exceeded
49 Execution timed out 1075 ms 127208 KB Time limit exceeded
50 Execution timed out 1085 ms 105092 KB Time limit exceeded
51 Execution timed out 1095 ms 105020 KB Time limit exceeded
52 Execution timed out 1101 ms 103500 KB Time limit exceeded
53 Execution timed out 1101 ms 102672 KB Time limit exceeded
54 Execution timed out 1098 ms 75464 KB Time limit exceeded
55 Execution timed out 1101 ms 73436 KB Time limit exceeded
56 Execution timed out 1094 ms 89440 KB Time limit exceeded
57 Execution timed out 1097 ms 67948 KB Time limit exceeded
58 Execution timed out 1100 ms 73356 KB Time limit exceeded
59 Execution timed out 1095 ms 70008 KB Time limit exceeded
60 Execution timed out 1097 ms 93020 KB Time limit exceeded
61 Execution timed out 1098 ms 118256 KB Time limit exceeded
62 Execution timed out 1099 ms 117084 KB Time limit exceeded
63 Execution timed out 1096 ms 119852 KB Time limit exceeded
64 Execution timed out 1097 ms 66300 KB Time limit exceeded
65 Execution timed out 1100 ms 100912 KB Time limit exceeded
66 Execution timed out 1098 ms 98944 KB Time limit exceeded
67 Execution timed out 1090 ms 107252 KB Time limit exceeded
68 Execution timed out 1106 ms 110924 KB Time limit exceeded
69 Execution timed out 1099 ms 67180 KB Time limit exceeded
70 Execution timed out 1101 ms 33884 KB Time limit exceeded
71 Execution timed out 1094 ms 56272 KB Time limit exceeded
72 Execution timed out 1104 ms 62784 KB Time limit exceeded
73 Execution timed out 1089 ms 67552 KB Time limit exceeded
74 Execution timed out 1093 ms 69056 KB Time limit exceeded
75 Execution timed out 1095 ms 72152 KB Time limit exceeded
76 Execution timed out 1088 ms 73536 KB Time limit exceeded
77 Execution timed out 1102 ms 75584 KB Time limit exceeded
78 Execution timed out 1084 ms 74700 KB Time limit exceeded
79 Incorrect 679 ms 31448 KB Output isn't correct
80 Incorrect 700 ms 32748 KB Output isn't correct
81 Execution timed out 1088 ms 34532 KB Time limit exceeded
82 Execution timed out 1101 ms 79072 KB Time limit exceeded
83 Execution timed out 1104 ms 78528 KB Time limit exceeded
84 Incorrect 609 ms 26604 KB Output isn't correct
85 Execution timed out 1093 ms 73936 KB Time limit exceeded
86 Execution timed out 1084 ms 120252 KB Time limit exceeded
87 Execution timed out 1102 ms 72604 KB Time limit exceeded
88 Execution timed out 1095 ms 77632 KB Time limit exceeded
89 Execution timed out 1092 ms 91980 KB Time limit exceeded
90 Execution timed out 1084 ms 52876 KB Time limit exceeded
91 Execution timed out 1102 ms 82268 KB Time limit exceeded
92 Execution timed out 1086 ms 89180 KB Time limit exceeded
93 Execution timed out 1097 ms 118060 KB Time limit exceeded
94 Execution timed out 1057 ms 91504 KB Time limit exceeded
95 Execution timed out 1099 ms 78784 KB Time limit exceeded
96 Execution timed out 1084 ms 78528 KB Time limit exceeded
97 Execution timed out 1103 ms 120256 KB Time limit exceeded
98 Execution timed out 1095 ms 79808 KB Time limit exceeded
99 Execution timed out 1095 ms 90284 KB Time limit exceeded
100 Execution timed out 1090 ms 116680 KB Time limit exceeded