# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
877342 | marcid | Bomb (IZhO17_bomb) | C++17 | 275 ms | 12880 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;
#define int long long
const int maxn = 2501;
char field[maxn][maxn];
int mn1=maxn,mn2=maxn;
int count(string s) {
int cnt = 1; int best = s.size();
bool ret = false;
for (int i = 0; i < s.size(); i++) {
if (s[i]=='1') ret=true;
} for (int i = 1; i < s.size(); i++) {
if (s[i]=='1' && s[i-1]=='1') cnt++;
else if(s[i-1]=='1' && s[i]=='0') {best=min(best,cnt);cnt=1;}
}
return (ret ? best : 0);
}
signed main() {
int n,m; cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> field[i][j];
}
} for (int i = 1; i <= n; i++) {
string t="";
for (int j = 1; j <= m; j++) t+=field[i][j];
int x = count(t);
if (x>0) mn1=min(mn1,x);
} for (int j = 1; j <= m; j++) {
string t="";
for (int i = 1; i <= n; i++) t+=field[i][j];
int x = count(t);
if (x>0) mn2=min(mn2, x);
}
cout << ((maxn==mn1 || maxn==mn2) ? 0 : mn1*mn2) << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |