#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n,m;
int arr[300005];
int cnt[25];
vector<int>sub[100005];
pi2 f(pi2 a, int b, int c){
if(b>=a.first.first){
if(a.first.second==c){
a.first={b,c};
}
else{
a.second=a.first;
a.first={b,c};
}
}
else if(b>=a.second.first){
if(a.first.second!=c) a.second={b,c};
}
return a;
}
pi2 memo[25][100005];
bool vis[25][100005];
void out(int x){
for(int y=0;y<m;y++){
cout << ((x&(1<<y))>0);
}
cout << endl;
}
pi2 dp(int index, int mask){
if(index>=m){
pi2 cur={{0,0},{0,0}};
int num=__builtin_popcount(mask);
if(sub[mask].size()==1){
cur.first={num,sub[mask][0]};
}
else if(sub[mask].size()>1){
cur.first={num,sub[mask][0]};
cur.second={num,sub[mask][1]};
}
//if(cur.first.first>=4){
//show2(a,cur.first.first,b,cur.first.second);
//show2(c,cur.second.first,d,cur.second.second);
//cout << "mask ";
//out(mask);
//}
return cur;
}
if(vis[index][mask]) return memo[index][mask];
pi2 ans=dp(index+1,mask);
if(mask&(1<<index)){
pi2 hold=dp(index+1,mask^(1<<index));
ans=f(ans,hold.first.first,hold.first.second);
ans=f(ans,hold.second.first,hold.second.second);
}
vis[index][mask]=true;
return memo[index][mask]=ans;
}
void dfs(int index, int mask){
if(mask==0) return;
if(sub[mask].size()>=2) return;
if(sub[mask].size()>0&&sub[mask][0]==index) return;
if(sub[mask].size()>1&&sub[mask][1]==index) return;
sub[mask].push_back(index);
for(int x=0;x<m;x++){
if(mask&(1<<x)){
dfs(index,mask^(1<<x));
}
}
}
void solve(){
cin >> n >> m;
int temp;
for(int x=0;x<n;x++){
int inv=0;
for(int y=0;y<m;y++){
cin >> temp;
arr[x]+=temp*(1<<y);
cnt[y]+=temp;
inv+=(1-temp)*(1<<y);
}
dfs(x,inv);
}
for(int x=0;x<n;x++){
for(int y=0;y<m;y++){
if(arr[x]&(1<<y)) cnt[y]--;
}
int crit=n/2;
int safe=0;
int hold=0;
for(int y=0;y<m;y++){
if(cnt[y]>crit) safe++;
if(cnt[y]==crit) hold+=(1<<y);
}
//show2(x,x,safe,safe);
//out(hold);
pi2 take=dp(0,hold);
//show2(aa,take.first.first,bb,take.first.second);
//show2(cc,take.second.first,dd,take.second.second);
if(take.first.second==x){
safe+=take.second.first;
}
else safe+=take.first.first;
for(int y=0;y<m;y++){
if(arr[x]&(1<<y)) cnt[y]++;
}
cout << safe << "\n";
}
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
9 ms |
29276 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
8536 KB |
Output is correct |
5 |
Runtime error |
7 ms |
8796 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
9 ms |
29276 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
8536 KB |
Output is correct |
5 |
Runtime error |
7 ms |
8796 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
48 ms |
11464 KB |
Output is correct |
3 |
Correct |
41 ms |
11372 KB |
Output is correct |
4 |
Correct |
31 ms |
8796 KB |
Output is correct |
5 |
Correct |
47 ms |
11468 KB |
Output is correct |
6 |
Correct |
32 ms |
8896 KB |
Output is correct |
7 |
Correct |
48 ms |
11488 KB |
Output is correct |
8 |
Correct |
1 ms |
6744 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8536 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
2 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
48 ms |
11464 KB |
Output is correct |
3 |
Correct |
41 ms |
11372 KB |
Output is correct |
4 |
Correct |
31 ms |
8796 KB |
Output is correct |
5 |
Correct |
47 ms |
11468 KB |
Output is correct |
6 |
Correct |
32 ms |
8896 KB |
Output is correct |
7 |
Correct |
48 ms |
11488 KB |
Output is correct |
8 |
Correct |
1 ms |
6744 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8536 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
2 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
3 ms |
12636 KB |
Output is correct |
20 |
Correct |
170 ms |
32728 KB |
Output is correct |
21 |
Correct |
148 ms |
29964 KB |
Output is correct |
22 |
Correct |
148 ms |
29824 KB |
Output is correct |
23 |
Correct |
137 ms |
32852 KB |
Output is correct |
24 |
Correct |
151 ms |
32740 KB |
Output is correct |
25 |
Correct |
173 ms |
32592 KB |
Output is correct |
26 |
Correct |
183 ms |
32692 KB |
Output is correct |
27 |
Correct |
4 ms |
24920 KB |
Output is correct |
28 |
Correct |
2 ms |
10584 KB |
Output is correct |
29 |
Correct |
2 ms |
12632 KB |
Output is correct |
30 |
Correct |
2 ms |
14684 KB |
Output is correct |
31 |
Correct |
3 ms |
16728 KB |
Output is correct |
32 |
Correct |
3 ms |
18776 KB |
Output is correct |
33 |
Correct |
3 ms |
20828 KB |
Output is correct |
34 |
Correct |
4 ms |
22876 KB |
Output is correct |
35 |
Correct |
4 ms |
25024 KB |
Output is correct |
36 |
Correct |
4 ms |
25176 KB |
Output is correct |
37 |
Correct |
2 ms |
10588 KB |
Output is correct |
38 |
Correct |
2 ms |
12636 KB |
Output is correct |
39 |
Correct |
2 ms |
14684 KB |
Output is correct |
40 |
Correct |
3 ms |
16992 KB |
Output is correct |
41 |
Correct |
3 ms |
18780 KB |
Output is correct |
42 |
Correct |
3 ms |
20828 KB |
Output is correct |
43 |
Correct |
3 ms |
22876 KB |
Output is correct |
44 |
Correct |
3 ms |
24924 KB |
Output is correct |
45 |
Correct |
4 ms |
25180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
48 ms |
11464 KB |
Output is correct |
3 |
Correct |
41 ms |
11372 KB |
Output is correct |
4 |
Correct |
31 ms |
8796 KB |
Output is correct |
5 |
Correct |
47 ms |
11468 KB |
Output is correct |
6 |
Correct |
32 ms |
8896 KB |
Output is correct |
7 |
Correct |
48 ms |
11488 KB |
Output is correct |
8 |
Correct |
1 ms |
6744 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8536 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
2 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
3 ms |
12636 KB |
Output is correct |
20 |
Correct |
170 ms |
32728 KB |
Output is correct |
21 |
Correct |
148 ms |
29964 KB |
Output is correct |
22 |
Correct |
148 ms |
29824 KB |
Output is correct |
23 |
Correct |
137 ms |
32852 KB |
Output is correct |
24 |
Correct |
151 ms |
32740 KB |
Output is correct |
25 |
Correct |
173 ms |
32592 KB |
Output is correct |
26 |
Correct |
183 ms |
32692 KB |
Output is correct |
27 |
Correct |
4 ms |
24920 KB |
Output is correct |
28 |
Correct |
2 ms |
10584 KB |
Output is correct |
29 |
Correct |
2 ms |
12632 KB |
Output is correct |
30 |
Correct |
2 ms |
14684 KB |
Output is correct |
31 |
Correct |
3 ms |
16728 KB |
Output is correct |
32 |
Correct |
3 ms |
18776 KB |
Output is correct |
33 |
Correct |
3 ms |
20828 KB |
Output is correct |
34 |
Correct |
4 ms |
22876 KB |
Output is correct |
35 |
Correct |
4 ms |
25024 KB |
Output is correct |
36 |
Correct |
4 ms |
25176 KB |
Output is correct |
37 |
Correct |
2 ms |
10588 KB |
Output is correct |
38 |
Correct |
2 ms |
12636 KB |
Output is correct |
39 |
Correct |
2 ms |
14684 KB |
Output is correct |
40 |
Correct |
3 ms |
16992 KB |
Output is correct |
41 |
Correct |
3 ms |
18780 KB |
Output is correct |
42 |
Correct |
3 ms |
20828 KB |
Output is correct |
43 |
Correct |
3 ms |
22876 KB |
Output is correct |
44 |
Correct |
3 ms |
24924 KB |
Output is correct |
45 |
Correct |
4 ms |
25180 KB |
Output is correct |
46 |
Correct |
4 ms |
29272 KB |
Output is correct |
47 |
Correct |
266 ms |
51992 KB |
Output is correct |
48 |
Correct |
235 ms |
42832 KB |
Output is correct |
49 |
Correct |
236 ms |
42964 KB |
Output is correct |
50 |
Correct |
203 ms |
43708 KB |
Output is correct |
51 |
Correct |
177 ms |
43604 KB |
Output is correct |
52 |
Correct |
243 ms |
43712 KB |
Output is correct |
53 |
Correct |
271 ms |
52528 KB |
Output is correct |
54 |
Correct |
9 ms |
41952 KB |
Output is correct |
55 |
Correct |
5 ms |
35420 KB |
Output is correct |
56 |
Correct |
6 ms |
37640 KB |
Output is correct |
57 |
Correct |
6 ms |
41560 KB |
Output is correct |
58 |
Correct |
6 ms |
41820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8536 KB |
Output is correct |
2 |
Correct |
48 ms |
11464 KB |
Output is correct |
3 |
Correct |
41 ms |
11372 KB |
Output is correct |
4 |
Correct |
31 ms |
8796 KB |
Output is correct |
5 |
Correct |
47 ms |
11468 KB |
Output is correct |
6 |
Correct |
32 ms |
8896 KB |
Output is correct |
7 |
Correct |
48 ms |
11488 KB |
Output is correct |
8 |
Correct |
1 ms |
6744 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
2 ms |
8540 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8536 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
2 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
2 ms |
8540 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
3 ms |
12636 KB |
Output is correct |
20 |
Correct |
170 ms |
32728 KB |
Output is correct |
21 |
Correct |
148 ms |
29964 KB |
Output is correct |
22 |
Correct |
148 ms |
29824 KB |
Output is correct |
23 |
Correct |
137 ms |
32852 KB |
Output is correct |
24 |
Correct |
151 ms |
32740 KB |
Output is correct |
25 |
Correct |
173 ms |
32592 KB |
Output is correct |
26 |
Correct |
183 ms |
32692 KB |
Output is correct |
27 |
Correct |
4 ms |
24920 KB |
Output is correct |
28 |
Correct |
2 ms |
10584 KB |
Output is correct |
29 |
Correct |
2 ms |
12632 KB |
Output is correct |
30 |
Correct |
2 ms |
14684 KB |
Output is correct |
31 |
Correct |
3 ms |
16728 KB |
Output is correct |
32 |
Correct |
3 ms |
18776 KB |
Output is correct |
33 |
Correct |
3 ms |
20828 KB |
Output is correct |
34 |
Correct |
4 ms |
22876 KB |
Output is correct |
35 |
Correct |
4 ms |
25024 KB |
Output is correct |
36 |
Correct |
4 ms |
25176 KB |
Output is correct |
37 |
Correct |
2 ms |
10588 KB |
Output is correct |
38 |
Correct |
2 ms |
12636 KB |
Output is correct |
39 |
Correct |
2 ms |
14684 KB |
Output is correct |
40 |
Correct |
3 ms |
16992 KB |
Output is correct |
41 |
Correct |
3 ms |
18780 KB |
Output is correct |
42 |
Correct |
3 ms |
20828 KB |
Output is correct |
43 |
Correct |
3 ms |
22876 KB |
Output is correct |
44 |
Correct |
3 ms |
24924 KB |
Output is correct |
45 |
Correct |
4 ms |
25180 KB |
Output is correct |
46 |
Correct |
4 ms |
29272 KB |
Output is correct |
47 |
Correct |
266 ms |
51992 KB |
Output is correct |
48 |
Correct |
235 ms |
42832 KB |
Output is correct |
49 |
Correct |
236 ms |
42964 KB |
Output is correct |
50 |
Correct |
203 ms |
43708 KB |
Output is correct |
51 |
Correct |
177 ms |
43604 KB |
Output is correct |
52 |
Correct |
243 ms |
43712 KB |
Output is correct |
53 |
Correct |
271 ms |
52528 KB |
Output is correct |
54 |
Correct |
9 ms |
41952 KB |
Output is correct |
55 |
Correct |
5 ms |
35420 KB |
Output is correct |
56 |
Correct |
6 ms |
37640 KB |
Output is correct |
57 |
Correct |
6 ms |
41560 KB |
Output is correct |
58 |
Correct |
6 ms |
41820 KB |
Output is correct |
59 |
Correct |
290 ms |
50116 KB |
Output is correct |
60 |
Runtime error |
8 ms |
9964 KB |
Execution killed with signal 11 |
61 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10588 KB |
Output is correct |
2 |
Correct |
9 ms |
29276 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
2 ms |
8536 KB |
Output is correct |
5 |
Runtime error |
7 ms |
8796 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |