#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
const int mod = 1000000007;
const int N = 200005;
string a[N+2], dp[N+2];
void solve(){
int n, m;
cin>>n>>m;
int r = n+1, c = m+1;
for(int i = 0; i < n; i++){
cin>>a[i];
}
for(int i = 0; i < n; i++){
int cnt = 0;
for(int j = 0; j < m; j++){
cnt += a[i][j] == '1';
if(a[i][j] == '0'){
if(cnt)c = min(c, cnt);
cnt = 0;
}
}
if(cnt)c = min(c, cnt);
}
for(int j = 0; j < m; j++){
int cnt = 0;
for(int i = 0; i < n; i++){
cnt += a[i][j] == '1';
if(a[i][j] == '0'){
if(cnt)r = min(r, cnt);
cnt = 0;
}
}
if(cnt)r = min(r, cnt);
}
if(r == n + 1 || c == n + 1){
cout<<0<<' '<<0;
}
else cout<<r<<' '<<c;
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int tt = 1;
//cin>>tt;
while(tt--){
solve();
cout<<'\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |