# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
26327 |
2017-06-29T08:17:10 Z |
khsoo01 |
Raspad (COI17_raspad) |
C++11 |
|
199 ms |
87076 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<ll, ll,ll> tp;
const ll N = 100005, M = 55;
ll n, m, ans[N], par[M], b[2][M], cc, ic, uc, cnt;
char ipt[N][M];
vector<tp> qry[N];
void parse (char I[], ll B[]) {
for(ll i=1;i<=m;i++) {
if(I[i] == '1') {
if(I[i-1] != '1') cc++;
B[i] = cc;
}
else B[i] = 0;
}
}
ll Find (ll P) {
if(par[P] == P) return P;
return par[P] = Find(par[P]);
}
void Union (ll A, ll B, vector<tp> &V) {
A = Find(A); B = Find(B);
if(A == B) return;
if(A > B) swap(A, B);
par[B] = A;
cc--;
if(A <= ic && B <= ic) {
V.push_back(tp(A, B, cnt));
cnt = 0;
}
}
int main()
{
scanf("%lld%lld",&n,&m);
for(ll i=1;i<=n;i++) {
scanf("%s",ipt[i]+1);
}
for(ll i=1;i<=n;i++) {
cc = 0; cnt = 1;
parse(ipt[i], b[1]);
ans[i] = ans[i-1] + cc; ic = cc;
if(i == 1) continue;
parse(ipt[i-1], b[0]);
ll lft = i-1; uc = cc - ic;
for(ll j=1;j<=cc;j++) par[j] = j;
for(ll j=1;j<=m;j++) {
ll A = b[0][j], B = b[1][j];
if(A && B) Union(A, B, qry[i]);
}
for(auto &T : qry[i-1]) {
ll A, B, C; tie(A, B, C) = T;
ans[i] += C * (cc - uc);
uc--; lft -= C; cnt += C;
Union(A+ic, B+ic, qry[i]);
}
ans[i] += lft * (cc - uc);
}
ll sum = 0;
for(ll i=1;i<=n;i++) sum += ans[i];
printf("%lld\n",sum);
}
Compilation message
raspad.cpp: In function 'int main()':
raspad.cpp:41:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld",&n,&m);
^
raspad.cpp:43:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",ipt[i]+1);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
10516 KB |
Output is correct |
2 |
Correct |
0 ms |
10516 KB |
Output is correct |
3 |
Correct |
0 ms |
10516 KB |
Output is correct |
4 |
Correct |
0 ms |
10516 KB |
Output is correct |
5 |
Correct |
0 ms |
10516 KB |
Output is correct |
6 |
Correct |
0 ms |
10516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
10516 KB |
Output is correct |
2 |
Correct |
0 ms |
10516 KB |
Output is correct |
3 |
Correct |
0 ms |
10516 KB |
Output is correct |
4 |
Correct |
0 ms |
10516 KB |
Output is correct |
5 |
Correct |
0 ms |
10516 KB |
Output is correct |
6 |
Correct |
0 ms |
10516 KB |
Output is correct |
7 |
Correct |
0 ms |
10516 KB |
Output is correct |
8 |
Correct |
0 ms |
10516 KB |
Output is correct |
9 |
Correct |
0 ms |
10648 KB |
Output is correct |
10 |
Correct |
3 ms |
10912 KB |
Output is correct |
11 |
Correct |
3 ms |
10648 KB |
Output is correct |
12 |
Correct |
0 ms |
10780 KB |
Output is correct |
13 |
Correct |
3 ms |
10648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
10516 KB |
Output is correct |
2 |
Correct |
46 ms |
10780 KB |
Output is correct |
3 |
Correct |
59 ms |
15268 KB |
Output is correct |
4 |
Correct |
16 ms |
10516 KB |
Output is correct |
5 |
Correct |
13 ms |
10648 KB |
Output is correct |
6 |
Correct |
63 ms |
12232 KB |
Output is correct |
7 |
Correct |
36 ms |
20812 KB |
Output is correct |
8 |
Correct |
33 ms |
12100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
10516 KB |
Output is correct |
2 |
Correct |
0 ms |
10516 KB |
Output is correct |
3 |
Correct |
0 ms |
10516 KB |
Output is correct |
4 |
Correct |
0 ms |
10516 KB |
Output is correct |
5 |
Correct |
0 ms |
10516 KB |
Output is correct |
6 |
Correct |
0 ms |
10516 KB |
Output is correct |
7 |
Correct |
0 ms |
10516 KB |
Output is correct |
8 |
Correct |
0 ms |
10516 KB |
Output is correct |
9 |
Correct |
0 ms |
10648 KB |
Output is correct |
10 |
Correct |
3 ms |
10912 KB |
Output is correct |
11 |
Correct |
3 ms |
10648 KB |
Output is correct |
12 |
Correct |
0 ms |
10780 KB |
Output is correct |
13 |
Correct |
3 ms |
10648 KB |
Output is correct |
14 |
Correct |
13 ms |
10516 KB |
Output is correct |
15 |
Correct |
46 ms |
10780 KB |
Output is correct |
16 |
Correct |
59 ms |
15268 KB |
Output is correct |
17 |
Correct |
16 ms |
10516 KB |
Output is correct |
18 |
Correct |
13 ms |
10648 KB |
Output is correct |
19 |
Correct |
63 ms |
12232 KB |
Output is correct |
20 |
Correct |
36 ms |
20812 KB |
Output is correct |
21 |
Correct |
33 ms |
12100 KB |
Output is correct |
22 |
Correct |
99 ms |
12496 KB |
Output is correct |
23 |
Correct |
199 ms |
33748 KB |
Output is correct |
24 |
Correct |
179 ms |
37048 KB |
Output is correct |
25 |
Correct |
143 ms |
12628 KB |
Output is correct |
26 |
Correct |
113 ms |
49588 KB |
Output is correct |
27 |
Correct |
116 ms |
15532 KB |
Output is correct |
28 |
Correct |
166 ms |
29392 KB |
Output is correct |
29 |
Correct |
153 ms |
15400 KB |
Output is correct |
30 |
Correct |
69 ms |
10516 KB |
Output is correct |
31 |
Correct |
179 ms |
87076 KB |
Output is correct |
32 |
Correct |
149 ms |
48928 KB |
Output is correct |
33 |
Correct |
113 ms |
21472 KB |
Output is correct |
34 |
Correct |
139 ms |
24244 KB |
Output is correct |