#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("FEEDING.INP");
ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 7, inf = 1e9;
const int mxn = 1e5 + 5;
int n, m;
pii son[(1 << 20)];
char c[300005][21];
int cnt[(1 << 20)], val[20], mask[300005];
pair<pii, pii>dp[(1 << 20)];
bool ckmx(pii a, pii b){
if(b.fi == 0)return(1);
return(a.se > b.se);
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++){
for(int j = 0; j < m; j++){
cin >> c[i][j];
if(c[i][j] == '1'){
mask[i] += (1 << j);
val[j]++;
}
}
mask[i] = (((1 << m) - 1) ^ mask[i]);
if(!son[mask[i]].fi)son[mask[i]].fi = i;
else if(!son[mask[i]].se)son[mask[i]].se = i;
}
for(int i = 0; i < (1 << m); i++){
cnt[i] = __builtin_popcount(i);
}
for(int i = 0; i < m; i++){
for(int j = 0; j < (1 << m); j++){
if(!(j & (1 << i))){
int &x = son[j].fi, &y = son[j].se, candx = son[j ^ (1 << i)].fi, candy = son[j ^ (1 << i)].se;
if(x){
if(!y){
if(candx && candx != x)y = candx;
else if(candy && candy != x)y = candy;
}
}else{
if(candx){
x = candx;
if(candy)y = candy;
}else{
if(candy)x = candy;
}
}
}
}
}
for(int i = 0; i < (1 << m); i++){
dp[i] = make_pair(make_pair(son[i].first, ((son[i].first ? cnt[i] : 0))), make_pair(son[i].second, (son[i].second ? cnt[i] : 0)));
}
for(int i = 0; i < m; i++){
for(int j = 0; j < (1 << m); j++){
if(j & (1 << i)){
auto [cand1, cand2] = dp[j ^ (1 << i)];
if(cand1.fi && ckmx(cand1, dp[j].se)){
dp[j].se = cand1;
if(ckmx(dp[j].se, dp[j].fi)){
swap(dp[j].fi, dp[j].se);
}
if(dp[j].fi.fi == dp[j].se.fi){
dp[j].se = make_pair(0, 0);
}
}if(cand2.fi && ckmx(cand2, dp[j].se)){
dp[j].se = cand2;
if(ckmx(dp[j].se, dp[j].fi)){
swap(dp[j].fi, dp[j].se);
}
if(dp[j].fi.fi == dp[j].se.fi){
dp[j].se = make_pair(0, 0);
}
}
}
}
}
for(int i = 1; i <= n; i++){
int mask = 0, ans = 0;
for(int j = 0; j < m; j++){
if(c[i][j] == '1'){
val[j]--;
}
if(val[j] == n / 2){
mask += (1 << j); ans++;
}else if(val[j] > n / 2)ans++;
if(c[i][j] == '1'){
val[j]++;
}
}
//cout << mask << " ";
auto [res1, res2] = dp[mask];
if(res1.fi != i){
//cout << res1.se << " " << " " << cnt[mask] << " ";
cout << ans - (cnt[mask] - res1.se) << "\n";
}else{
cout << ans - (cnt[mask] - res2.se) << "\n";
}
}
return(0);
}
Compilation message
council.cpp: In function 'int main()':
council.cpp:82:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
82 | auto [cand1, cand2] = dp[j ^ (1 << i)];
| ^
council.cpp:123:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
123 | auto [res1, res2] = dp[mask];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
65 ms |
24964 KB |
Output is correct |
6 |
Correct |
68 ms |
20944 KB |
Output is correct |
7 |
Correct |
70 ms |
23380 KB |
Output is correct |
8 |
Correct |
76 ms |
23472 KB |
Output is correct |
9 |
Correct |
89 ms |
28564 KB |
Output is correct |
10 |
Correct |
88 ms |
22732 KB |
Output is correct |
11 |
Correct |
77 ms |
24912 KB |
Output is correct |
12 |
Correct |
91 ms |
28612 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 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 |
1 ms |
724 KB |
Output is correct |
42 |
Correct |
1 ms |
724 KB |
Output is correct |
43 |
Correct |
1 ms |
724 KB |
Output is correct |
44 |
Correct |
1 ms |
728 KB |
Output is correct |
45 |
Correct |
2 ms |
784 KB |
Output is correct |
46 |
Correct |
9 ms |
3376 KB |
Output is correct |
47 |
Correct |
7 ms |
3284 KB |
Output is correct |
48 |
Correct |
8 ms |
3540 KB |
Output is correct |
49 |
Correct |
8 ms |
3284 KB |
Output is correct |
50 |
Correct |
9 ms |
3956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
65 ms |
24964 KB |
Output is correct |
6 |
Correct |
68 ms |
20944 KB |
Output is correct |
7 |
Correct |
70 ms |
23380 KB |
Output is correct |
8 |
Correct |
76 ms |
23472 KB |
Output is correct |
9 |
Correct |
89 ms |
28564 KB |
Output is correct |
10 |
Correct |
88 ms |
22732 KB |
Output is correct |
11 |
Correct |
77 ms |
24912 KB |
Output is correct |
12 |
Correct |
91 ms |
28612 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 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 |
1 ms |
724 KB |
Output is correct |
42 |
Correct |
1 ms |
724 KB |
Output is correct |
43 |
Correct |
1 ms |
724 KB |
Output is correct |
44 |
Correct |
1 ms |
728 KB |
Output is correct |
45 |
Correct |
2 ms |
784 KB |
Output is correct |
46 |
Correct |
9 ms |
3376 KB |
Output is correct |
47 |
Correct |
7 ms |
3284 KB |
Output is correct |
48 |
Correct |
8 ms |
3540 KB |
Output is correct |
49 |
Correct |
8 ms |
3284 KB |
Output is correct |
50 |
Correct |
9 ms |
3956 KB |
Output is correct |
51 |
Correct |
61 ms |
21032 KB |
Output is correct |
52 |
Correct |
69 ms |
29256 KB |
Output is correct |
53 |
Correct |
94 ms |
29248 KB |
Output is correct |
54 |
Correct |
91 ms |
29208 KB |
Output is correct |
55 |
Correct |
1 ms |
352 KB |
Output is correct |
56 |
Correct |
13 ms |
4124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
25 ms |
9368 KB |
Output is correct |
3 |
Correct |
26 ms |
9388 KB |
Output is correct |
4 |
Correct |
25 ms |
8796 KB |
Output is correct |
5 |
Correct |
32 ms |
9436 KB |
Output is correct |
6 |
Correct |
25 ms |
8780 KB |
Output is correct |
7 |
Correct |
39 ms |
9352 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
25 ms |
9368 KB |
Output is correct |
3 |
Correct |
26 ms |
9388 KB |
Output is correct |
4 |
Correct |
25 ms |
8796 KB |
Output is correct |
5 |
Correct |
32 ms |
9436 KB |
Output is correct |
6 |
Correct |
25 ms |
8780 KB |
Output is correct |
7 |
Correct |
39 ms |
9352 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
84 ms |
14072 KB |
Output is correct |
21 |
Incorrect |
78 ms |
13468 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
25 ms |
9368 KB |
Output is correct |
3 |
Correct |
26 ms |
9388 KB |
Output is correct |
4 |
Correct |
25 ms |
8796 KB |
Output is correct |
5 |
Correct |
32 ms |
9436 KB |
Output is correct |
6 |
Correct |
25 ms |
8780 KB |
Output is correct |
7 |
Correct |
39 ms |
9352 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
84 ms |
14072 KB |
Output is correct |
21 |
Incorrect |
78 ms |
13468 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
25 ms |
9368 KB |
Output is correct |
3 |
Correct |
26 ms |
9388 KB |
Output is correct |
4 |
Correct |
25 ms |
8796 KB |
Output is correct |
5 |
Correct |
32 ms |
9436 KB |
Output is correct |
6 |
Correct |
25 ms |
8780 KB |
Output is correct |
7 |
Correct |
39 ms |
9352 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
84 ms |
14072 KB |
Output is correct |
21 |
Incorrect |
78 ms |
13468 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
65 ms |
24964 KB |
Output is correct |
6 |
Correct |
68 ms |
20944 KB |
Output is correct |
7 |
Correct |
70 ms |
23380 KB |
Output is correct |
8 |
Correct |
76 ms |
23472 KB |
Output is correct |
9 |
Correct |
89 ms |
28564 KB |
Output is correct |
10 |
Correct |
88 ms |
22732 KB |
Output is correct |
11 |
Correct |
77 ms |
24912 KB |
Output is correct |
12 |
Correct |
91 ms |
28612 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 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 |
1 ms |
724 KB |
Output is correct |
42 |
Correct |
1 ms |
724 KB |
Output is correct |
43 |
Correct |
1 ms |
724 KB |
Output is correct |
44 |
Correct |
1 ms |
728 KB |
Output is correct |
45 |
Correct |
2 ms |
784 KB |
Output is correct |
46 |
Correct |
9 ms |
3376 KB |
Output is correct |
47 |
Correct |
7 ms |
3284 KB |
Output is correct |
48 |
Correct |
8 ms |
3540 KB |
Output is correct |
49 |
Correct |
8 ms |
3284 KB |
Output is correct |
50 |
Correct |
9 ms |
3956 KB |
Output is correct |
51 |
Correct |
61 ms |
21032 KB |
Output is correct |
52 |
Correct |
69 ms |
29256 KB |
Output is correct |
53 |
Correct |
94 ms |
29248 KB |
Output is correct |
54 |
Correct |
91 ms |
29208 KB |
Output is correct |
55 |
Correct |
1 ms |
352 KB |
Output is correct |
56 |
Correct |
13 ms |
4124 KB |
Output is correct |
57 |
Correct |
1 ms |
340 KB |
Output is correct |
58 |
Correct |
25 ms |
9368 KB |
Output is correct |
59 |
Correct |
26 ms |
9388 KB |
Output is correct |
60 |
Correct |
25 ms |
8796 KB |
Output is correct |
61 |
Correct |
32 ms |
9436 KB |
Output is correct |
62 |
Correct |
25 ms |
8780 KB |
Output is correct |
63 |
Correct |
39 ms |
9352 KB |
Output is correct |
64 |
Correct |
0 ms |
340 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
0 ms |
340 KB |
Output is correct |
67 |
Correct |
1 ms |
340 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
1 ms |
340 KB |
Output is correct |
70 |
Correct |
0 ms |
340 KB |
Output is correct |
71 |
Correct |
1 ms |
340 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
1 ms |
344 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
1 ms |
340 KB |
Output is correct |
76 |
Correct |
84 ms |
14072 KB |
Output is correct |
77 |
Incorrect |
78 ms |
13468 KB |
Output isn't correct |
78 |
Halted |
0 ms |
0 KB |
- |