Submission #686403

# Submission time Handle Problem Language Result Execution time Memory
686403 2023-01-25T08:59:34 Z pragmatist Bomb (IZhO17_bomb) C++17
0 / 100
67 ms 131072 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];
vector<int> d[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]);
}

bool may(int x) {
	for(auto h : d[x]) {
        int w = x / h;
        memset(e, 0, sizeof(e));
       	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) return 1;
   	}
   	return 0;
}

void solve() {
	cin >> n >> m;
	for(int i = 1; i <= n * m; ++i) {
		for(int j = i; j <= n * m; j += i) {
			d[j].pb(i);
		}
	}
	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 l = 1, r = n * m, ans = 0;
	while(l <= r) {
		int mid = (l + r) >> 1;
		if(may(mid)) {
			ans = mid;
			l = mid + 1;
		} else
			r = mid - 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;
}
# Verdict Execution time Memory Grader output
1 Runtime error 65 ms 131072 KB Execution killed with signal 9
2 Runtime error 61 ms 131072 KB Execution killed with signal 9
3 Runtime error 59 ms 131072 KB Execution killed with signal 9
4 Runtime error 59 ms 131072 KB Execution killed with signal 9
5 Runtime error 61 ms 131072 KB Execution killed with signal 9
6 Runtime error 56 ms 131072 KB Execution killed with signal 9
7 Runtime error 54 ms 131072 KB Execution killed with signal 9
8 Runtime error 52 ms 131072 KB Execution killed with signal 9
9 Runtime error 57 ms 131072 KB Execution killed with signal 9
10 Runtime error 58 ms 131072 KB Execution killed with signal 9
11 Runtime error 53 ms 131072 KB Execution killed with signal 9
12 Runtime error 52 ms 131072 KB Execution killed with signal 9
13 Runtime error 53 ms 131072 KB Execution killed with signal 9
14 Runtime error 54 ms 131072 KB Execution killed with signal 9
15 Runtime error 55 ms 131072 KB Execution killed with signal 9
16 Runtime error 56 ms 131072 KB Execution killed with signal 9
17 Runtime error 64 ms 131072 KB Execution killed with signal 9
18 Runtime error 52 ms 131072 KB Execution killed with signal 9
19 Runtime error 52 ms 131072 KB Execution killed with signal 9
20 Runtime error 52 ms 131072 KB Execution killed with signal 9
21 Runtime error 52 ms 131072 KB Execution killed with signal 9
22 Runtime error 52 ms 131072 KB Execution killed with signal 9
23 Runtime error 52 ms 131072 KB Execution killed with signal 9
24 Runtime error 60 ms 131072 KB Execution killed with signal 9
25 Runtime error 57 ms 131072 KB Execution killed with signal 9
26 Runtime error 61 ms 131072 KB Execution killed with signal 9
27 Runtime error 56 ms 131072 KB Execution killed with signal 9
28 Runtime error 52 ms 131072 KB Execution killed with signal 9
29 Runtime error 54 ms 131072 KB Execution killed with signal 9
30 Runtime error 57 ms 131072 KB Execution killed with signal 9
31 Runtime error 64 ms 131072 KB Execution killed with signal 9
32 Runtime error 55 ms 131072 KB Execution killed with signal 9
33 Runtime error 55 ms 131072 KB Execution killed with signal 9
34 Runtime error 57 ms 131072 KB Execution killed with signal 9
35 Runtime error 54 ms 131072 KB Execution killed with signal 9
36 Runtime error 57 ms 131072 KB Execution killed with signal 9
37 Runtime error 55 ms 131072 KB Execution killed with signal 9
38 Runtime error 62 ms 131072 KB Execution killed with signal 9
39 Runtime error 56 ms 131072 KB Execution killed with signal 9
40 Runtime error 53 ms 131072 KB Execution killed with signal 9
41 Runtime error 49 ms 131072 KB Execution killed with signal 9
42 Runtime error 54 ms 131072 KB Execution killed with signal 9
43 Runtime error 64 ms 131072 KB Execution killed with signal 9
44 Runtime error 52 ms 131072 KB Execution killed with signal 9
45 Runtime error 54 ms 131072 KB Execution killed with signal 9
46 Runtime error 52 ms 131072 KB Execution killed with signal 9
47 Runtime error 60 ms 131072 KB Execution killed with signal 9
48 Runtime error 54 ms 131072 KB Execution killed with signal 9
49 Runtime error 57 ms 131072 KB Execution killed with signal 9
50 Runtime error 59 ms 131072 KB Execution killed with signal 9
51 Runtime error 58 ms 131072 KB Execution killed with signal 9
52 Runtime error 49 ms 131072 KB Execution killed with signal 9
53 Runtime error 52 ms 131072 KB Execution killed with signal 9
54 Runtime error 51 ms 131072 KB Execution killed with signal 9
55 Runtime error 60 ms 131072 KB Execution killed with signal 9
56 Runtime error 52 ms 131072 KB Execution killed with signal 9
57 Runtime error 54 ms 131072 KB Execution killed with signal 9
58 Runtime error 61 ms 131072 KB Execution killed with signal 9
59 Runtime error 51 ms 131072 KB Execution killed with signal 9
60 Runtime error 54 ms 131072 KB Execution killed with signal 9
61 Runtime error 63 ms 131072 KB Execution killed with signal 9
62 Runtime error 55 ms 131072 KB Execution killed with signal 9
63 Runtime error 55 ms 131072 KB Execution killed with signal 9
64 Runtime error 67 ms 131072 KB Execution killed with signal 9
65 Runtime error 54 ms 131072 KB Execution killed with signal 9
66 Runtime error 61 ms 131072 KB Execution killed with signal 9
67 Runtime error 55 ms 131072 KB Execution killed with signal 9
68 Runtime error 61 ms 131072 KB Execution killed with signal 9
69 Runtime error 55 ms 131072 KB Execution killed with signal 9
70 Runtime error 55 ms 131072 KB Execution killed with signal 9
71 Runtime error 53 ms 131072 KB Execution killed with signal 9
72 Runtime error 53 ms 131072 KB Execution killed with signal 9
73 Runtime error 55 ms 131072 KB Execution killed with signal 9
74 Runtime error 57 ms 131072 KB Execution killed with signal 9
75 Runtime error 56 ms 131072 KB Execution killed with signal 9
76 Runtime error 58 ms 131072 KB Execution killed with signal 9
77 Runtime error 54 ms 131072 KB Execution killed with signal 9
78 Runtime error 51 ms 131072 KB Execution killed with signal 9
79 Runtime error 52 ms 131072 KB Execution killed with signal 9
80 Runtime error 53 ms 131072 KB Execution killed with signal 9
81 Runtime error 56 ms 131072 KB Execution killed with signal 9
82 Runtime error 55 ms 131072 KB Execution killed with signal 9
83 Runtime error 54 ms 131072 KB Execution killed with signal 9
84 Runtime error 54 ms 131072 KB Execution killed with signal 9
85 Runtime error 55 ms 131072 KB Execution killed with signal 9
86 Runtime error 62 ms 131072 KB Execution killed with signal 9
87 Runtime error 58 ms 131072 KB Execution killed with signal 9
88 Runtime error 56 ms 131072 KB Execution killed with signal 9
89 Runtime error 53 ms 131072 KB Execution killed with signal 9
90 Runtime error 54 ms 131072 KB Execution killed with signal 9
91 Runtime error 53 ms 131072 KB Execution killed with signal 9
92 Runtime error 53 ms 131072 KB Execution killed with signal 9
93 Runtime error 53 ms 131072 KB Execution killed with signal 9
94 Runtime error 59 ms 131072 KB Execution killed with signal 9
95 Runtime error 57 ms 131072 KB Execution killed with signal 9
96 Runtime error 52 ms 131072 KB Execution killed with signal 9
97 Runtime error 49 ms 131072 KB Execution killed with signal 9
98 Runtime error 61 ms 131072 KB Execution killed with signal 9
99 Runtime error 55 ms 131072 KB Execution killed with signal 9
100 Runtime error 54 ms 131072 KB Execution killed with signal 9