#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
const ll N = 2e6 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 350;
ll n,m;
ll a[N][21], res[N], cnt[N];
pll mn[N];
void to_thic_cau(){
cin >> n >> m;
for(int i = 0; i < (1 << m);i++) mn[i] = {inf, inf};
for(int i = 1; i <= n;i++){
for(int j = 0; j < m;j++){
cin >> a[i][j];
if(a[i][j] == 1) cnt[j]++;
}
}
for(int i = 1; i <= n;i++){
for(int msk = 0; msk < (1 << m);msk++){
ll cur = 0;
for(int j = 0; j < m;j++) if((msk & (1 << j)) && a[i][j] == 1) cur++;
if(cur < mn[msk].F) mn[msk].S = mn[msk].F, mn[msk].F = cur;
else if(cur < mn[msk].S) mn[msk].S = cur;
}
}
for(int i = 1; i <= n;i++){
ll msk = 0, cur = 0, res = 0;
for(int j = 0; j < m;j++){
if(a[i][j] == 1) cnt[j]--;
if(cnt[j] == n / 2) msk |= (1 << j), res++;
else if(cnt[j] > n / 2) res++;
}
for(int j = 0; j < m;j++) if((msk & (1 << j)) && a[i][j] == 1) cur++;
if(cur == mn[msk].F) res -= mn[msk].S;
else res -= mn[msk].F;
for(int j = 0; j < m;j++) if(a[i][j] == 1) cnt[j]++;
cout << res << "\n";
assert(res >= 0);
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll tc = 1;
//cin >> tc;
while(tc--) to_thic_cau();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2452 ms |
16872 KB |
Output is correct |
6 |
Execution timed out |
4066 ms |
16732 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2452 ms |
16872 KB |
Output is correct |
6 |
Execution timed out |
4066 ms |
16732 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
66 ms |
51212 KB |
Output is correct |
3 |
Correct |
57 ms |
51284 KB |
Output is correct |
4 |
Correct |
51 ms |
50772 KB |
Output is correct |
5 |
Correct |
70 ms |
51172 KB |
Output is correct |
6 |
Correct |
48 ms |
50772 KB |
Output is correct |
7 |
Correct |
68 ms |
51284 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
468 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 |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
66 ms |
51212 KB |
Output is correct |
3 |
Correct |
57 ms |
51284 KB |
Output is correct |
4 |
Correct |
51 ms |
50772 KB |
Output is correct |
5 |
Correct |
70 ms |
51172 KB |
Output is correct |
6 |
Correct |
48 ms |
50772 KB |
Output is correct |
7 |
Correct |
68 ms |
51284 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
468 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 |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
860 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Execution timed out |
4089 ms |
53032 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
66 ms |
51212 KB |
Output is correct |
3 |
Correct |
57 ms |
51284 KB |
Output is correct |
4 |
Correct |
51 ms |
50772 KB |
Output is correct |
5 |
Correct |
70 ms |
51172 KB |
Output is correct |
6 |
Correct |
48 ms |
50772 KB |
Output is correct |
7 |
Correct |
68 ms |
51284 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
468 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 |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
860 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Execution timed out |
4089 ms |
53032 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
66 ms |
51212 KB |
Output is correct |
3 |
Correct |
57 ms |
51284 KB |
Output is correct |
4 |
Correct |
51 ms |
50772 KB |
Output is correct |
5 |
Correct |
70 ms |
51172 KB |
Output is correct |
6 |
Correct |
48 ms |
50772 KB |
Output is correct |
7 |
Correct |
68 ms |
51284 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
468 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 |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
860 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Execution timed out |
4089 ms |
53032 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
464 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2452 ms |
16872 KB |
Output is correct |
6 |
Execution timed out |
4066 ms |
16732 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |