# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1055423 | makrav | Bomb (IZhO17_bomb) | C++17 | 38 ms | 13564 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second
void solve() {
int n, m; cin >> n >> m;
vector<string> s(n);
for (int i = 0; i < n; i++) cin >> s[i];
int wg = m, hg = n;
for (int i = 0; i < n; i++) {
int lf = -1;
for (int j = 0; j < m; j++) {
if (s[i][j] == '1' && lf == -1) lf = j;
else if (s[i][j] == '0' && lf != -1) {
wg = min(wg, j - lf);
lf = -1;
}
}
if (lf != -1) wg = min(wg, m - lf);
}
for (int j = 0; j < m; j++) {
int lf = -1;
for (int i = 0; i < n; i++) {
if (s[i][j] == '1' && lf == -1) lf = i;
else if (s[i][j] == '0' && lf != -1) {
hg = min(hg, i - lf);
lf = -1;
}
}
if (lf != -1) hg = min(hg, n - lf);
}
cout << wg * hg << '\n';
}
signed main() {
int tt = 1;
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
cin >> tt;
#else
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#endif
while (tt--) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |