답안 #686405

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
686405 2023-01-25T09:02:09 Z pragmatist Bomb (IZhO17_bomb) C++17
15 / 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]);
}

bool may(int x) {
    vector<int> v;
    for(int h = 1; h <= sqrt(x); ++h) {
        if(x % h == 0) {
            v.pb(h), v.pb(x / h);
        }
    }
    for(auto h : v) {
        int w = x / h;
       	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; ++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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 17 ms 26452 KB Output is correct
4 Correct 15 ms 26452 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Incorrect 1 ms 340 KB Output isn't correct
8 Incorrect 0 ms 468 KB Output isn't correct
9 Correct 0 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Incorrect 1 ms 468 KB Output isn't correct
12 Correct 0 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Incorrect 1 ms 468 KB Output isn't correct
16 Incorrect 1 ms 468 KB Output isn't correct
17 Incorrect 2 ms 980 KB Output isn't correct
18 Correct 2 ms 980 KB Output is correct
19 Incorrect 3 ms 1364 KB Output isn't correct
20 Incorrect 6 ms 1368 KB Output isn't correct
21 Correct 2 ms 852 KB Output is correct
22 Incorrect 3 ms 1108 KB Output isn't correct
23 Incorrect 5 ms 1364 KB Output isn't correct
24 Incorrect 2 ms 1236 KB Output isn't correct
25 Incorrect 5 ms 1460 KB Output isn't correct
26 Incorrect 5 ms 1364 KB Output isn't correct
27 Correct 39 ms 4052 KB Output is correct
28 Incorrect 40 ms 4180 KB Output isn't correct
29 Incorrect 195 ms 5516 KB Output isn't correct
30 Incorrect 187 ms 6356 KB Output isn't correct
31 Incorrect 59 ms 4948 KB Output isn't correct
32 Incorrect 62 ms 5808 KB Output isn't correct
33 Incorrect 148 ms 6632 KB Output isn't correct
34 Correct 46 ms 4692 KB Output is correct
35 Incorrect 138 ms 6632 KB Output isn't correct
36 Incorrect 143 ms 6636 KB Output isn't correct
37 Incorrect 1 ms 468 KB Output isn't correct
38 Execution timed out 1088 ms 55520 KB Time limit exceeded
39 Incorrect 1 ms 468 KB Output isn't correct
40 Incorrect 460 ms 15576 KB Output isn't correct
41 Incorrect 1 ms 468 KB Output isn't correct
42 Incorrect 7 ms 1364 KB Output isn't correct
43 Execution timed out 1091 ms 55500 KB Time limit exceeded
44 Incorrect 209 ms 6612 KB Output isn't correct
45 Execution timed out 1096 ms 55424 KB Time limit exceeded
46 Execution timed out 1081 ms 55500 KB Time limit exceeded
47 Execution timed out 1091 ms 55544 KB Time limit exceeded
48 Execution timed out 1082 ms 55472 KB Time limit exceeded
49 Execution timed out 1096 ms 55508 KB Time limit exceeded
50 Execution timed out 1098 ms 55504 KB Time limit exceeded
51 Execution timed out 1099 ms 55416 KB Time limit exceeded
52 Execution timed out 1096 ms 55548 KB Time limit exceeded
53 Execution timed out 1090 ms 55500 KB Time limit exceeded
54 Execution timed out 1095 ms 55484 KB Time limit exceeded
55 Execution timed out 1102 ms 55500 KB Time limit exceeded
56 Execution timed out 1095 ms 55408 KB Time limit exceeded
57 Execution timed out 1098 ms 55412 KB Time limit exceeded
58 Execution timed out 1095 ms 55396 KB Time limit exceeded
59 Execution timed out 1086 ms 55396 KB Time limit exceeded
60 Execution timed out 1094 ms 55416 KB Time limit exceeded
61 Execution timed out 1093 ms 55500 KB Time limit exceeded
62 Execution timed out 1096 ms 55500 KB Time limit exceeded
63 Execution timed out 1090 ms 55512 KB Time limit exceeded
64 Execution timed out 1098 ms 55500 KB Time limit exceeded
65 Execution timed out 1057 ms 55420 KB Time limit exceeded
66 Execution timed out 1100 ms 55496 KB Time limit exceeded
67 Execution timed out 1089 ms 55500 KB Time limit exceeded
68 Execution timed out 1093 ms 55472 KB Time limit exceeded
69 Execution timed out 1085 ms 55500 KB Time limit exceeded
70 Execution timed out 1099 ms 44364 KB Time limit exceeded
71 Execution timed out 1086 ms 55500 KB Time limit exceeded
72 Execution timed out 1074 ms 55440 KB Time limit exceeded
73 Execution timed out 1099 ms 55500 KB Time limit exceeded
74 Execution timed out 1093 ms 55500 KB Time limit exceeded
75 Execution timed out 1099 ms 55408 KB Time limit exceeded
76 Execution timed out 1090 ms 55496 KB Time limit exceeded
77 Execution timed out 1092 ms 55476 KB Time limit exceeded
78 Execution timed out 1088 ms 55500 KB Time limit exceeded
79 Execution timed out 1097 ms 55500 KB Time limit exceeded
80 Execution timed out 1084 ms 55480 KB Time limit exceeded
81 Execution timed out 1052 ms 55500 KB Time limit exceeded
82 Execution timed out 1093 ms 55604 KB Time limit exceeded
83 Execution timed out 1097 ms 55524 KB Time limit exceeded
84 Execution timed out 1099 ms 55500 KB Time limit exceeded
85 Execution timed out 1089 ms 55404 KB Time limit exceeded
86 Execution timed out 1087 ms 55500 KB Time limit exceeded
87 Execution timed out 1094 ms 55428 KB Time limit exceeded
88 Execution timed out 1090 ms 55500 KB Time limit exceeded
89 Execution timed out 1093 ms 55412 KB Time limit exceeded
90 Execution timed out 1092 ms 44452 KB Time limit exceeded
91 Execution timed out 1090 ms 55488 KB Time limit exceeded
92 Execution timed out 1098 ms 55432 KB Time limit exceeded
93 Execution timed out 1101 ms 55500 KB Time limit exceeded
94 Execution timed out 1090 ms 55500 KB Time limit exceeded
95 Execution timed out 1099 ms 55464 KB Time limit exceeded
96 Execution timed out 1103 ms 55500 KB Time limit exceeded
97 Execution timed out 1060 ms 55528 KB Time limit exceeded
98 Execution timed out 1091 ms 55376 KB Time limit exceeded
99 Execution timed out 1087 ms 55488 KB Time limit exceeded
100 Execution timed out 1068 ms 55500 KB Time limit exceeded