#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define F first
#define S second
using namespace std;
typedef int ll;
ll n,m,ans,x,p[50009];
bool b[1005][55];
char c;
ll gp(ll z)
{
if(p[z]==z)
return z;
return p[z]=gp(p[z]);
}
void mrg(ll xo,ll yo)
{
xo=gp(xo),yo=gp(yo);
if(xo==yo)
return;
x--;
p[yo]=xo;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m;
for(ll i=0; i<n; i++)
for(ll j=0; j<m; j++)
{
cin>>c;
b[i][j]=c-'0';
}
for(ll i=0; i<n; i++)
{
x=0;
for(ll j=0; j<m; j++)
if(b[i][j])
{
p[i*m+j]=i*m+j;
x++;
if(b[i][j-1])
mrg(i*m+j-1,i*m+j);
}
ans+=x;
for(ll j=i+1; j<n; j++)
{
for(ll k=0; k<m; k++)
{
if(b[j][k])
{
p[j*m+k]=j*m+k;
x++;
if(b[j][k-1])
mrg(j*m+k-1,j*m+k);
if(b[j-1][k])
mrg(j*m+k-m,j*m+k);
}
}
ans+=x;
}
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
125 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
333 ms |
596 KB |
Output is correct |
10 |
Correct |
104 ms |
488 KB |
Output is correct |
11 |
Correct |
193 ms |
588 KB |
Output is correct |
12 |
Correct |
61 ms |
460 KB |
Output is correct |
13 |
Correct |
151 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
1100 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
125 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
333 ms |
596 KB |
Output is correct |
10 |
Correct |
104 ms |
488 KB |
Output is correct |
11 |
Correct |
193 ms |
588 KB |
Output is correct |
12 |
Correct |
61 ms |
460 KB |
Output is correct |
13 |
Correct |
151 ms |
716 KB |
Output is correct |
14 |
Runtime error |
3 ms |
1100 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |