#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define pil pair<int,long long>
#define pll pair<long long,long long>
#define eb emplace_back
const int maxn=3e5+9,maxm=20;
bool a[maxn][maxm+1];
int sum[maxm+1];
int mask[maxn];
pii f[maxn];
pii add(pii p,int q){
if (q==0)return p;
if (p.fi==0){
p.fi=q;
}
else if (p.fi!=0&&p.se==0){
p.se=q;
}
return p;
}
pair<pii,pii> g[maxn];
int nn(int x){
return __builtin_popcount(x);
}
int b[4];
pii add(pii &p, pii &q){
b[0]=p.fi,b[1]=p.se,b[2]=q.fi,b[3]=q.se;
sort(b,b+4);
vector<int>vcl;
vcl.pb(b[0]);
for1(i,1,3){
if (b[i]!=b[i-1])vcl.pb(b[i]);
}
if (sz(vcl)==0)return {0,0};
if (sz(vcl)==1)return {vcl[0],0};
return {vcl[0],vcl[1]};
}
#define piii pair<pii,pii>
pii c[4];
piii update(piii p, piii q){
c[0]=p.fi,c[1]=p.se,c[2]=q.fi,c[3]=q.se;
sort(c,c+4,greater<pii>());
if (c[0].fi==0)return {{0,0},{0,0}};
for1(i,1,3){
if (c[i].se!=c[0].se){
return {c[0],c[i]};
}
}
return {c[0],{0,0}};
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("temp.INP","r",stdin);
//freopen("temp.OUT","w",stdout);
int n,m;
cin>>n>>m;
for1(i,1,n){
for1(j,1,m){
cin>>a[i][j];
sum[j]+=a[i][j];
if (!a[i][j]){
mask[i]|=(1<<(j-1));
//cout<<i<<" "<<j<<'\n';
}
}
f[mask[i]]=add(f[mask[i]],i);
}
for1(j,0,m-1){
for2(i,(1<<m)-1,0){
if (i>>j&1){
f[i-(1<<j)]=add(f[i-(1<<j)],f[i].fi);
f[i-(1<<j)]=add(f[i-(1<<j)],f[i].se);
}
}
}
for1(i,0,(1<<m)-1){
if (f[i].fi)g[i].fi={nn(i),f[i].fi};
if (f[i].se)g[i].se={nn(i),f[i].se};
}
for1(i,0,(1<<m)-1){
for1(j,0,m-1){
if (i>>j&1){
g[i]=update(g[i],g[i-(1<<j)]);
}
}
}
int limit=n/2;
for1(i,1,n){
int msk=0;
int ans=0;
int turn=0;
for1(j,1,m){
int nw=sum[j]-a[i][j];
if (nw==limit){
//can be 0
msk+=(1<<(j-1));
//cout<<j<<'\n';
if (a[i][j]==0)turn++;
}
else if (nw>limit){
ans++;
}
}
//cout<<msk<<'\n';
if (turn==g[msk].fi.fi)ans+=g[msk].se.fi;
else ans+=g[msk].fi.fi;
cout<<ans<<'\n';
}
//cout<<g[1890].fi<<" "<<g[1890].se;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Runtime error |
209 ms |
29592 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Runtime error |
209 ms |
29592 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
48 ms |
8252 KB |
Output is correct |
3 |
Correct |
46 ms |
9316 KB |
Output is correct |
4 |
Correct |
33 ms |
8784 KB |
Output is correct |
5 |
Correct |
49 ms |
9420 KB |
Output is correct |
6 |
Correct |
41 ms |
8756 KB |
Output is correct |
7 |
Correct |
53 ms |
9332 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
0 ms |
328 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
48 ms |
8252 KB |
Output is correct |
3 |
Correct |
46 ms |
9316 KB |
Output is correct |
4 |
Correct |
33 ms |
8784 KB |
Output is correct |
5 |
Correct |
49 ms |
9420 KB |
Output is correct |
6 |
Correct |
41 ms |
8756 KB |
Output is correct |
7 |
Correct |
53 ms |
9332 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
0 ms |
328 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
224 KB |
Output is correct |
20 |
Correct |
181 ms |
14032 KB |
Output is correct |
21 |
Correct |
164 ms |
13500 KB |
Output is correct |
22 |
Correct |
183 ms |
13480 KB |
Output is correct |
23 |
Correct |
165 ms |
13160 KB |
Output is correct |
24 |
Correct |
169 ms |
14052 KB |
Output is correct |
25 |
Correct |
181 ms |
14200 KB |
Output is correct |
26 |
Correct |
183 ms |
14156 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
328 KB |
Output is correct |
32 |
Correct |
1 ms |
328 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
328 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
48 ms |
8252 KB |
Output is correct |
3 |
Correct |
46 ms |
9316 KB |
Output is correct |
4 |
Correct |
33 ms |
8784 KB |
Output is correct |
5 |
Correct |
49 ms |
9420 KB |
Output is correct |
6 |
Correct |
41 ms |
8756 KB |
Output is correct |
7 |
Correct |
53 ms |
9332 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
0 ms |
328 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
224 KB |
Output is correct |
20 |
Correct |
181 ms |
14032 KB |
Output is correct |
21 |
Correct |
164 ms |
13500 KB |
Output is correct |
22 |
Correct |
183 ms |
13480 KB |
Output is correct |
23 |
Correct |
165 ms |
13160 KB |
Output is correct |
24 |
Correct |
169 ms |
14052 KB |
Output is correct |
25 |
Correct |
181 ms |
14200 KB |
Output is correct |
26 |
Correct |
183 ms |
14156 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
328 KB |
Output is correct |
32 |
Correct |
1 ms |
328 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
328 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
253 ms |
16800 KB |
Output is correct |
48 |
Correct |
236 ms |
16060 KB |
Output is correct |
49 |
Correct |
234 ms |
16052 KB |
Output is correct |
50 |
Correct |
251 ms |
15912 KB |
Output is correct |
51 |
Correct |
202 ms |
16856 KB |
Output is correct |
52 |
Correct |
238 ms |
16860 KB |
Output is correct |
53 |
Correct |
284 ms |
17064 KB |
Output is correct |
54 |
Correct |
3 ms |
724 KB |
Output is correct |
55 |
Correct |
5 ms |
724 KB |
Output is correct |
56 |
Correct |
5 ms |
724 KB |
Output is correct |
57 |
Correct |
4 ms |
712 KB |
Output is correct |
58 |
Correct |
4 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
48 ms |
8252 KB |
Output is correct |
3 |
Correct |
46 ms |
9316 KB |
Output is correct |
4 |
Correct |
33 ms |
8784 KB |
Output is correct |
5 |
Correct |
49 ms |
9420 KB |
Output is correct |
6 |
Correct |
41 ms |
8756 KB |
Output is correct |
7 |
Correct |
53 ms |
9332 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
0 ms |
328 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
224 KB |
Output is correct |
20 |
Correct |
181 ms |
14032 KB |
Output is correct |
21 |
Correct |
164 ms |
13500 KB |
Output is correct |
22 |
Correct |
183 ms |
13480 KB |
Output is correct |
23 |
Correct |
165 ms |
13160 KB |
Output is correct |
24 |
Correct |
169 ms |
14052 KB |
Output is correct |
25 |
Correct |
181 ms |
14200 KB |
Output is correct |
26 |
Correct |
183 ms |
14156 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
0 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
328 KB |
Output is correct |
32 |
Correct |
1 ms |
328 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
0 ms |
328 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
253 ms |
16800 KB |
Output is correct |
48 |
Correct |
236 ms |
16060 KB |
Output is correct |
49 |
Correct |
234 ms |
16052 KB |
Output is correct |
50 |
Correct |
251 ms |
15912 KB |
Output is correct |
51 |
Correct |
202 ms |
16856 KB |
Output is correct |
52 |
Correct |
238 ms |
16860 KB |
Output is correct |
53 |
Correct |
284 ms |
17064 KB |
Output is correct |
54 |
Correct |
3 ms |
724 KB |
Output is correct |
55 |
Correct |
5 ms |
724 KB |
Output is correct |
56 |
Correct |
5 ms |
724 KB |
Output is correct |
57 |
Correct |
4 ms |
712 KB |
Output is correct |
58 |
Correct |
4 ms |
724 KB |
Output is correct |
59 |
Correct |
282 ms |
19476 KB |
Output is correct |
60 |
Correct |
145 ms |
10256 KB |
Output is correct |
61 |
Correct |
150 ms |
10768 KB |
Output is correct |
62 |
Correct |
155 ms |
11028 KB |
Output is correct |
63 |
Correct |
305 ms |
19228 KB |
Output is correct |
64 |
Correct |
332 ms |
21300 KB |
Output is correct |
65 |
Correct |
339 ms |
21320 KB |
Output is correct |
66 |
Correct |
296 ms |
20428 KB |
Output is correct |
67 |
Correct |
275 ms |
21220 KB |
Output is correct |
68 |
Correct |
305 ms |
21220 KB |
Output is correct |
69 |
Correct |
333 ms |
21592 KB |
Output is correct |
70 |
Correct |
25 ms |
3280 KB |
Output is correct |
71 |
Correct |
30 ms |
3364 KB |
Output is correct |
72 |
Correct |
33 ms |
3368 KB |
Output is correct |
73 |
Correct |
30 ms |
3284 KB |
Output is correct |
74 |
Correct |
35 ms |
3412 KB |
Output is correct |
75 |
Correct |
32 ms |
3584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Runtime error |
209 ms |
29592 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |