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;
long long n, m, v[1005][55], ans; char c;
/*int par[1005][55];
inline int kompinx(int a1, int a2, int b1, int b2){
if (par[a1][a2]==a1*m+a2) return par[a1][a2];
par[b1][b2] = kompinx((par[a1][a2]-1)/m+1, (par[a1][a2]-1)%m+1, b1, b2);
}*/
bool bio[1005][55];
void dfs(int x, int y){
bio[x][y]=0;
if (bio[x+1][y]) dfs(x+1, y);
if (bio[x-1][y]) dfs(x-1, y);
if (bio[x][y+1]) dfs(x, y+1);
if (bio[x][y-1]) dfs(x, y-1);
}
long long ufind (int l, int r){
int sol=0;
for (int i=l; i<=r; i++)
for (int j=1; j<=m; j++)
bio[i][j]=v[i][j];
for (int i=l; i<=r; i++)
for (int j=1; j<=m; j++)
if (bio[i][j]){
sol++;
dfs(i, j);
}
return sol;
}
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i=1; i<=n; i++){
for (int j=1; j<=m; j++){
cin >> c;
v[i][j] = c-'0';
}
}
for (int l=1; l<=n; l++){
for (int r=l; r<=n; r++){
ans+=ufind(l, r); //ans+=cur;
}
} cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |