#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m; cin >> n >> m;
vector <vector<int>> a(n, vector <int> (m));
for ( auto &u: a ){
for ( auto &v: u ) cin >> v;
}
vector <int> cnt(m);
for ( int i = 0; i < n; i++ ){
for ( int j = 0; j < m; j++ ){
cnt[j] += a[i][j];
}
}
int tot = 0;
for ( auto &x: cnt ){
tot += (x >= n / 2);
}
const int S = 1 << m;
vector <ar<int,2>> us(S, {-1, -1});
for ( int i = 0; i < n; i++ ){
int b = 0;
for ( int j = 0; j < m; j++ ){
b |= a[i][j] << j;
}
if ( us[b][0] != -1 ){
swap(us[b][0], us[b][1]);
}
us[b][0] = i;
}
if ( m <= 17 ){
vector <vector<vector<int>>> lst(S, vector <vector<int>> (m + 1));
for ( int i = 0; i < S; i++ ){
for ( int j = 0; j < S; j++ ){
int b = __builtin_popcount(i & j);
if ( us[j][0] != -1 ){
lst[i][b].pb(us[j][0]);
}
if ( us[j][1] != -1 ){
lst[i][b].pb(us[j][1]);
}
}
}
for ( auto &u: lst ){
for ( auto &v: u ){
sort(all(v));
}
}
for ( int i = 0; i < n; i++ ){
auto tmp = cnt;
int b = 0, q = tot;
for ( int j = 0; j < m; j++ ){
if ( a[i][j] && tmp[j] == n / 2 ){
--q;
} tmp[j] -= a[i][j];
if ( tmp[j] == n / 2 ){
b |= 1 << j;
}
}
for ( int j = 0; j <= m; j++ ){
auto &tmp = lst[b][j];
if ( !tmp.empty() && (tmp[0] != i || tmp.back() != i) ){
q -= j;
break;
}
}
cout << q << ln;
}
} else{
for ( int i = 0; i < n; i++ ){
int mx = 0, q = tot;
auto tmp = cnt;
for ( int j = 0; j < m; j++ ){
if ( a[i][j] && cnt[j] == n / 2 ){
--q;
} cnt[j] -= a[i][j];
}
for ( int j = 0; j < n; j++ ){
if ( j == i ) continue;
int tq = q;
for ( int k = 0; k < m; k++ ){
if ( a[j][k] && cnt[k] == n / 2 ){
--tq;
}
}
chmax(mx, tq);
}
cout << mx << ln;
swap(tmp, cnt);
}
}
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
59 ms |
2124 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
16732 KB |
Output is correct |
6 |
Correct |
6 ms |
16732 KB |
Output is correct |
7 |
Correct |
3 ms |
16732 KB |
Output is correct |
8 |
Correct |
3 ms |
16732 KB |
Output is correct |
9 |
Correct |
12 ms |
16732 KB |
Output is correct |
10 |
Correct |
3 ms |
16732 KB |
Output is correct |
11 |
Correct |
4 ms |
16728 KB |
Output is correct |
12 |
Correct |
15 ms |
16732 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
5 ms |
860 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
6 ms |
1116 KB |
Output is correct |
31 |
Correct |
15 ms |
4272 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
2 ms |
604 KB |
Output is correct |
39 |
Correct |
6 ms |
1116 KB |
Output is correct |
40 |
Correct |
15 ms |
4364 KB |
Output is correct |
41 |
Correct |
928 ms |
10324 KB |
Output is correct |
42 |
Correct |
920 ms |
8556 KB |
Output is correct |
43 |
Correct |
973 ms |
11548 KB |
Output is correct |
44 |
Correct |
925 ms |
9068 KB |
Output is correct |
45 |
Correct |
930 ms |
11604 KB |
Output is correct |
46 |
Execution timed out |
4058 ms |
65504 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
59 ms |
2124 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
16732 KB |
Output is correct |
6 |
Correct |
6 ms |
16732 KB |
Output is correct |
7 |
Correct |
3 ms |
16732 KB |
Output is correct |
8 |
Correct |
3 ms |
16732 KB |
Output is correct |
9 |
Correct |
12 ms |
16732 KB |
Output is correct |
10 |
Correct |
3 ms |
16732 KB |
Output is correct |
11 |
Correct |
4 ms |
16728 KB |
Output is correct |
12 |
Correct |
15 ms |
16732 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
5 ms |
860 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
6 ms |
1116 KB |
Output is correct |
31 |
Correct |
15 ms |
4272 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
2 ms |
604 KB |
Output is correct |
39 |
Correct |
6 ms |
1116 KB |
Output is correct |
40 |
Correct |
15 ms |
4364 KB |
Output is correct |
41 |
Correct |
928 ms |
10324 KB |
Output is correct |
42 |
Correct |
920 ms |
8556 KB |
Output is correct |
43 |
Correct |
973 ms |
11548 KB |
Output is correct |
44 |
Correct |
925 ms |
9068 KB |
Output is correct |
45 |
Correct |
930 ms |
11604 KB |
Output is correct |
46 |
Execution timed out |
4058 ms |
65504 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
58 ms |
17396 KB |
Output is correct |
3 |
Correct |
56 ms |
17412 KB |
Output is correct |
4 |
Correct |
50 ms |
17488 KB |
Output is correct |
5 |
Correct |
67 ms |
17392 KB |
Output is correct |
6 |
Correct |
57 ms |
17652 KB |
Output is correct |
7 |
Correct |
62 ms |
17492 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
58 ms |
17396 KB |
Output is correct |
3 |
Correct |
56 ms |
17412 KB |
Output is correct |
4 |
Correct |
50 ms |
17488 KB |
Output is correct |
5 |
Correct |
67 ms |
17392 KB |
Output is correct |
6 |
Correct |
57 ms |
17652 KB |
Output is correct |
7 |
Correct |
62 ms |
17492 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
624 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
199 ms |
41568 KB |
Output is correct |
21 |
Correct |
167 ms |
33272 KB |
Output is correct |
22 |
Correct |
171 ms |
33296 KB |
Output is correct |
23 |
Correct |
163 ms |
36688 KB |
Output is correct |
24 |
Correct |
152 ms |
36440 KB |
Output is correct |
25 |
Correct |
270 ms |
58708 KB |
Output is correct |
26 |
Correct |
264 ms |
58708 KB |
Output is correct |
27 |
Correct |
5 ms |
860 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
2 ms |
604 KB |
Output is correct |
35 |
Correct |
8 ms |
1032 KB |
Output is correct |
36 |
Correct |
15 ms |
4188 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
684 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
6 ms |
1252 KB |
Output is correct |
45 |
Correct |
15 ms |
4184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
58 ms |
17396 KB |
Output is correct |
3 |
Correct |
56 ms |
17412 KB |
Output is correct |
4 |
Correct |
50 ms |
17488 KB |
Output is correct |
5 |
Correct |
67 ms |
17392 KB |
Output is correct |
6 |
Correct |
57 ms |
17652 KB |
Output is correct |
7 |
Correct |
62 ms |
17492 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
624 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
199 ms |
41568 KB |
Output is correct |
21 |
Correct |
167 ms |
33272 KB |
Output is correct |
22 |
Correct |
171 ms |
33296 KB |
Output is correct |
23 |
Correct |
163 ms |
36688 KB |
Output is correct |
24 |
Correct |
152 ms |
36440 KB |
Output is correct |
25 |
Correct |
270 ms |
58708 KB |
Output is correct |
26 |
Correct |
264 ms |
58708 KB |
Output is correct |
27 |
Correct |
5 ms |
860 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
2 ms |
604 KB |
Output is correct |
35 |
Correct |
8 ms |
1032 KB |
Output is correct |
36 |
Correct |
15 ms |
4188 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
684 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
6 ms |
1252 KB |
Output is correct |
45 |
Correct |
15 ms |
4184 KB |
Output is correct |
46 |
Correct |
59 ms |
2104 KB |
Output is correct |
47 |
Runtime error |
1909 ms |
1048576 KB |
Execution killed with signal 9 |
48 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
58 ms |
17396 KB |
Output is correct |
3 |
Correct |
56 ms |
17412 KB |
Output is correct |
4 |
Correct |
50 ms |
17488 KB |
Output is correct |
5 |
Correct |
67 ms |
17392 KB |
Output is correct |
6 |
Correct |
57 ms |
17652 KB |
Output is correct |
7 |
Correct |
62 ms |
17492 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
624 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
199 ms |
41568 KB |
Output is correct |
21 |
Correct |
167 ms |
33272 KB |
Output is correct |
22 |
Correct |
171 ms |
33296 KB |
Output is correct |
23 |
Correct |
163 ms |
36688 KB |
Output is correct |
24 |
Correct |
152 ms |
36440 KB |
Output is correct |
25 |
Correct |
270 ms |
58708 KB |
Output is correct |
26 |
Correct |
264 ms |
58708 KB |
Output is correct |
27 |
Correct |
5 ms |
860 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
2 ms |
604 KB |
Output is correct |
35 |
Correct |
8 ms |
1032 KB |
Output is correct |
36 |
Correct |
15 ms |
4188 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
684 KB |
Output is correct |
43 |
Correct |
2 ms |
604 KB |
Output is correct |
44 |
Correct |
6 ms |
1252 KB |
Output is correct |
45 |
Correct |
15 ms |
4184 KB |
Output is correct |
46 |
Correct |
59 ms |
2104 KB |
Output is correct |
47 |
Runtime error |
1909 ms |
1048576 KB |
Execution killed with signal 9 |
48 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
59 ms |
2124 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
16732 KB |
Output is correct |
6 |
Correct |
6 ms |
16732 KB |
Output is correct |
7 |
Correct |
3 ms |
16732 KB |
Output is correct |
8 |
Correct |
3 ms |
16732 KB |
Output is correct |
9 |
Correct |
12 ms |
16732 KB |
Output is correct |
10 |
Correct |
3 ms |
16732 KB |
Output is correct |
11 |
Correct |
4 ms |
16728 KB |
Output is correct |
12 |
Correct |
15 ms |
16732 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
5 ms |
860 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
604 KB |
Output is correct |
29 |
Correct |
2 ms |
604 KB |
Output is correct |
30 |
Correct |
6 ms |
1116 KB |
Output is correct |
31 |
Correct |
15 ms |
4272 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
604 KB |
Output is correct |
38 |
Correct |
2 ms |
604 KB |
Output is correct |
39 |
Correct |
6 ms |
1116 KB |
Output is correct |
40 |
Correct |
15 ms |
4364 KB |
Output is correct |
41 |
Correct |
928 ms |
10324 KB |
Output is correct |
42 |
Correct |
920 ms |
8556 KB |
Output is correct |
43 |
Correct |
973 ms |
11548 KB |
Output is correct |
44 |
Correct |
925 ms |
9068 KB |
Output is correct |
45 |
Correct |
930 ms |
11604 KB |
Output is correct |
46 |
Execution timed out |
4058 ms |
65504 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |