#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int>> bruh((1 << 20),{-1,-1});
vector<pair<int,int>> dp((1 << 20),{-1,-1});
vector<pair<int,int>> idk((1 << 20),{-1,-1});
vector<pair<int,int>> pos((1 << 20),{-1,-1});
void merge(int x, int c, int d) {
if(c == -1) {
return;
}
if(pos[x].first == c) {
idk[x] = {max(d,idk[x].first),idk[x].second};
}
else if(pos[x].second == c) {
idk[x] = {idk[x].first,max(idk[x].second,d)};
}
else {
if(d > idk[x].first) {
idk[x] = {d,idk[x].first};
pos[x] = {c,pos[x].first};
}
else if(d > idk[x].second) {
idk[x] = {idk[x].first,d};
pos[x] = {pos[x].first,c};
}
}
}
pair<int,int> calc(pair<int,int> a, int b) {
if(b == -1) {
return a;
}
if(a.first == -1) {
return {b,-1};
}
else if(a.second == -1 && a.first != b) {
return {a.first,b};
}
return a;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n,m,a;
cin >> n >> m;
vector<int> br(m);
vector<int> haha(n);
for(int i = 0; i < n; i++) {
int c = 0;
for(int j = 0; j < m; j++) {
cin >> a;
br[j]+=a;
c+=a*(1 << j);
}
bruh[c] = calc(bruh[c],i);
haha[i] = c;
}
for(int i = 0; i < (1 << m); i++) {
dp[i] = bruh[i];
for(int j = 0; j < m; j++) {
if((1 << j)&i) {
dp[i] = calc(dp[i],dp[i-(1 << j)].first);
dp[i] = calc(dp[i],dp[i-(1 << j)].second);
}
}
}
for(int i = (1 << m)-1; i >= 0; i--) {
int br = 0;
for(int j = 0; j < m; j++) {
if(((1 << j)&i) == 0) {
br++;
}
}
if(dp[i].first != -1) {
merge(i,dp[i].first,br);
}
if(dp[i].second != -1) {
merge(i,dp[i].second,br);
}
for(int j = 0; j < m; j++) {
if(((1 << j)&i) == 0) {
merge(i,pos[i+(1 << j)].first,idk[i+(1 << j)].first);
merge(i,pos[i+(1 << j)].second,idk[i+(1 << j)].second);
}
}
}
for(int i = 0; i < n; i++) {
int x = 0,ans = 0;
for(int j = 0; j < m; j++) {
int c = br[j];
if((1 << j)&haha[i]) {
c--;
}
if(c == n/2) {
x+=(1 << j);
}
if(c > n/2) {
ans++;
}
}
x = (1 << m)-1-x;
if(pos[x].first == i) {
cout << ans+idk[x].second << "\n";
}
else {
cout << ans+idk[x].first << "\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
33112 KB |
Output is correct |
2 |
Correct |
12 ms |
33116 KB |
Output is correct |
3 |
Correct |
12 ms |
33116 KB |
Output is correct |
4 |
Correct |
12 ms |
33116 KB |
Output is correct |
5 |
Correct |
207 ms |
33128 KB |
Output is correct |
6 |
Correct |
212 ms |
33116 KB |
Output is correct |
7 |
Incorrect |
223 ms |
33112 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
33112 KB |
Output is correct |
2 |
Correct |
12 ms |
33116 KB |
Output is correct |
3 |
Correct |
12 ms |
33116 KB |
Output is correct |
4 |
Correct |
12 ms |
33116 KB |
Output is correct |
5 |
Correct |
207 ms |
33128 KB |
Output is correct |
6 |
Correct |
212 ms |
33116 KB |
Output is correct |
7 |
Incorrect |
223 ms |
33112 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
33116 KB |
Output is correct |
2 |
Correct |
45 ms |
36124 KB |
Output is correct |
3 |
Correct |
48 ms |
36136 KB |
Output is correct |
4 |
Correct |
47 ms |
35540 KB |
Output is correct |
5 |
Correct |
51 ms |
36184 KB |
Output is correct |
6 |
Correct |
38 ms |
35408 KB |
Output is correct |
7 |
Correct |
53 ms |
36180 KB |
Output is correct |
8 |
Correct |
12 ms |
33116 KB |
Output is correct |
9 |
Correct |
12 ms |
33116 KB |
Output is correct |
10 |
Correct |
11 ms |
33240 KB |
Output is correct |
11 |
Correct |
12 ms |
33116 KB |
Output is correct |
12 |
Correct |
12 ms |
33116 KB |
Output is correct |
13 |
Correct |
11 ms |
33228 KB |
Output is correct |
14 |
Correct |
11 ms |
33116 KB |
Output is correct |
15 |
Correct |
12 ms |
33220 KB |
Output is correct |
16 |
Correct |
13 ms |
33112 KB |
Output is correct |
17 |
Correct |
12 ms |
33116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
33116 KB |
Output is correct |
2 |
Correct |
45 ms |
36124 KB |
Output is correct |
3 |
Correct |
48 ms |
36136 KB |
Output is correct |
4 |
Correct |
47 ms |
35540 KB |
Output is correct |
5 |
Correct |
51 ms |
36184 KB |
Output is correct |
6 |
Correct |
38 ms |
35408 KB |
Output is correct |
7 |
Correct |
53 ms |
36180 KB |
Output is correct |
8 |
Correct |
12 ms |
33116 KB |
Output is correct |
9 |
Correct |
12 ms |
33116 KB |
Output is correct |
10 |
Correct |
11 ms |
33240 KB |
Output is correct |
11 |
Correct |
12 ms |
33116 KB |
Output is correct |
12 |
Correct |
12 ms |
33116 KB |
Output is correct |
13 |
Correct |
11 ms |
33228 KB |
Output is correct |
14 |
Correct |
11 ms |
33116 KB |
Output is correct |
15 |
Correct |
12 ms |
33220 KB |
Output is correct |
16 |
Correct |
13 ms |
33112 KB |
Output is correct |
17 |
Correct |
12 ms |
33116 KB |
Output is correct |
18 |
Correct |
13 ms |
33092 KB |
Output is correct |
19 |
Correct |
12 ms |
33116 KB |
Output is correct |
20 |
Correct |
149 ms |
40728 KB |
Output is correct |
21 |
Correct |
160 ms |
40276 KB |
Output is correct |
22 |
Correct |
143 ms |
40224 KB |
Output is correct |
23 |
Correct |
128 ms |
41116 KB |
Output is correct |
24 |
Correct |
132 ms |
40728 KB |
Output is correct |
25 |
Correct |
149 ms |
40784 KB |
Output is correct |
26 |
Correct |
146 ms |
40852 KB |
Output is correct |
27 |
Correct |
13 ms |
33116 KB |
Output is correct |
28 |
Correct |
13 ms |
33112 KB |
Output is correct |
29 |
Correct |
13 ms |
33276 KB |
Output is correct |
30 |
Correct |
13 ms |
33216 KB |
Output is correct |
31 |
Correct |
13 ms |
33116 KB |
Output is correct |
32 |
Correct |
14 ms |
33072 KB |
Output is correct |
33 |
Correct |
12 ms |
33320 KB |
Output is correct |
34 |
Correct |
13 ms |
33116 KB |
Output is correct |
35 |
Correct |
13 ms |
33116 KB |
Output is correct |
36 |
Correct |
13 ms |
33116 KB |
Output is correct |
37 |
Correct |
13 ms |
33116 KB |
Output is correct |
38 |
Correct |
12 ms |
33116 KB |
Output is correct |
39 |
Correct |
12 ms |
33272 KB |
Output is correct |
40 |
Correct |
13 ms |
33116 KB |
Output is correct |
41 |
Correct |
17 ms |
33136 KB |
Output is correct |
42 |
Correct |
16 ms |
33112 KB |
Output is correct |
43 |
Correct |
13 ms |
33116 KB |
Output is correct |
44 |
Incorrect |
13 ms |
33316 KB |
Output isn't correct |
45 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
33116 KB |
Output is correct |
2 |
Correct |
45 ms |
36124 KB |
Output is correct |
3 |
Correct |
48 ms |
36136 KB |
Output is correct |
4 |
Correct |
47 ms |
35540 KB |
Output is correct |
5 |
Correct |
51 ms |
36184 KB |
Output is correct |
6 |
Correct |
38 ms |
35408 KB |
Output is correct |
7 |
Correct |
53 ms |
36180 KB |
Output is correct |
8 |
Correct |
12 ms |
33116 KB |
Output is correct |
9 |
Correct |
12 ms |
33116 KB |
Output is correct |
10 |
Correct |
11 ms |
33240 KB |
Output is correct |
11 |
Correct |
12 ms |
33116 KB |
Output is correct |
12 |
Correct |
12 ms |
33116 KB |
Output is correct |
13 |
Correct |
11 ms |
33228 KB |
Output is correct |
14 |
Correct |
11 ms |
33116 KB |
Output is correct |
15 |
Correct |
12 ms |
33220 KB |
Output is correct |
16 |
Correct |
13 ms |
33112 KB |
Output is correct |
17 |
Correct |
12 ms |
33116 KB |
Output is correct |
18 |
Correct |
13 ms |
33092 KB |
Output is correct |
19 |
Correct |
12 ms |
33116 KB |
Output is correct |
20 |
Correct |
149 ms |
40728 KB |
Output is correct |
21 |
Correct |
160 ms |
40276 KB |
Output is correct |
22 |
Correct |
143 ms |
40224 KB |
Output is correct |
23 |
Correct |
128 ms |
41116 KB |
Output is correct |
24 |
Correct |
132 ms |
40728 KB |
Output is correct |
25 |
Correct |
149 ms |
40784 KB |
Output is correct |
26 |
Correct |
146 ms |
40852 KB |
Output is correct |
27 |
Correct |
13 ms |
33116 KB |
Output is correct |
28 |
Correct |
13 ms |
33112 KB |
Output is correct |
29 |
Correct |
13 ms |
33276 KB |
Output is correct |
30 |
Correct |
13 ms |
33216 KB |
Output is correct |
31 |
Correct |
13 ms |
33116 KB |
Output is correct |
32 |
Correct |
14 ms |
33072 KB |
Output is correct |
33 |
Correct |
12 ms |
33320 KB |
Output is correct |
34 |
Correct |
13 ms |
33116 KB |
Output is correct |
35 |
Correct |
13 ms |
33116 KB |
Output is correct |
36 |
Correct |
13 ms |
33116 KB |
Output is correct |
37 |
Correct |
13 ms |
33116 KB |
Output is correct |
38 |
Correct |
12 ms |
33116 KB |
Output is correct |
39 |
Correct |
12 ms |
33272 KB |
Output is correct |
40 |
Correct |
13 ms |
33116 KB |
Output is correct |
41 |
Correct |
17 ms |
33136 KB |
Output is correct |
42 |
Correct |
16 ms |
33112 KB |
Output is correct |
43 |
Correct |
13 ms |
33116 KB |
Output is correct |
44 |
Incorrect |
13 ms |
33316 KB |
Output isn't correct |
45 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
33116 KB |
Output is correct |
2 |
Correct |
45 ms |
36124 KB |
Output is correct |
3 |
Correct |
48 ms |
36136 KB |
Output is correct |
4 |
Correct |
47 ms |
35540 KB |
Output is correct |
5 |
Correct |
51 ms |
36184 KB |
Output is correct |
6 |
Correct |
38 ms |
35408 KB |
Output is correct |
7 |
Correct |
53 ms |
36180 KB |
Output is correct |
8 |
Correct |
12 ms |
33116 KB |
Output is correct |
9 |
Correct |
12 ms |
33116 KB |
Output is correct |
10 |
Correct |
11 ms |
33240 KB |
Output is correct |
11 |
Correct |
12 ms |
33116 KB |
Output is correct |
12 |
Correct |
12 ms |
33116 KB |
Output is correct |
13 |
Correct |
11 ms |
33228 KB |
Output is correct |
14 |
Correct |
11 ms |
33116 KB |
Output is correct |
15 |
Correct |
12 ms |
33220 KB |
Output is correct |
16 |
Correct |
13 ms |
33112 KB |
Output is correct |
17 |
Correct |
12 ms |
33116 KB |
Output is correct |
18 |
Correct |
13 ms |
33092 KB |
Output is correct |
19 |
Correct |
12 ms |
33116 KB |
Output is correct |
20 |
Correct |
149 ms |
40728 KB |
Output is correct |
21 |
Correct |
160 ms |
40276 KB |
Output is correct |
22 |
Correct |
143 ms |
40224 KB |
Output is correct |
23 |
Correct |
128 ms |
41116 KB |
Output is correct |
24 |
Correct |
132 ms |
40728 KB |
Output is correct |
25 |
Correct |
149 ms |
40784 KB |
Output is correct |
26 |
Correct |
146 ms |
40852 KB |
Output is correct |
27 |
Correct |
13 ms |
33116 KB |
Output is correct |
28 |
Correct |
13 ms |
33112 KB |
Output is correct |
29 |
Correct |
13 ms |
33276 KB |
Output is correct |
30 |
Correct |
13 ms |
33216 KB |
Output is correct |
31 |
Correct |
13 ms |
33116 KB |
Output is correct |
32 |
Correct |
14 ms |
33072 KB |
Output is correct |
33 |
Correct |
12 ms |
33320 KB |
Output is correct |
34 |
Correct |
13 ms |
33116 KB |
Output is correct |
35 |
Correct |
13 ms |
33116 KB |
Output is correct |
36 |
Correct |
13 ms |
33116 KB |
Output is correct |
37 |
Correct |
13 ms |
33116 KB |
Output is correct |
38 |
Correct |
12 ms |
33116 KB |
Output is correct |
39 |
Correct |
12 ms |
33272 KB |
Output is correct |
40 |
Correct |
13 ms |
33116 KB |
Output is correct |
41 |
Correct |
17 ms |
33136 KB |
Output is correct |
42 |
Correct |
16 ms |
33112 KB |
Output is correct |
43 |
Correct |
13 ms |
33116 KB |
Output is correct |
44 |
Incorrect |
13 ms |
33316 KB |
Output isn't correct |
45 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
33112 KB |
Output is correct |
2 |
Correct |
12 ms |
33116 KB |
Output is correct |
3 |
Correct |
12 ms |
33116 KB |
Output is correct |
4 |
Correct |
12 ms |
33116 KB |
Output is correct |
5 |
Correct |
207 ms |
33128 KB |
Output is correct |
6 |
Correct |
212 ms |
33116 KB |
Output is correct |
7 |
Incorrect |
223 ms |
33112 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |