Submission #1086842

# Submission time Handle Problem Language Result Execution time Memory
1086842 2024-09-11T14:56:34 Z coldbr3w Council (JOI23_council) C++17
41 / 100
4000 ms 31828 KB
#include <bits/stdc++.h>
using namespace std;

#define ll int
#define pll pair<int, int>
#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 = 1e9;
const ll mod = 1e9 + 7;
const ll block = 350;
ll n,m;
ll a[N][21], res[N], cnt[N], dp[N], mp[N];
pll mn[N];
void trau(){
	for(int i = 1; i <= n;i++){
		for(int j = 1; j <= m;j++){
			cin >> a[i][j];
			if(a[i][j] == 1) cnt[j]++;
		}
	}
	for(int i = 1; i <= n;i++){
		for(int j = i + 1; j <= n;j++){
			for(int k = 1; k <= m;k++){
				if(a[i][k] == 1) cnt[k]--;
				if(a[j][k] == 1) cnt[k]--;
			}
			ll cur = 0;
			for(int k = 1; k <= m;k++){
				if(cnt[k] >= n / 2) cur++;
			}
			res[i] = max(res[i], cur); res[j] = max(res[j], cur);
			for(int k = 1; k <= m;k++){
				if(a[i][k] == 1) cnt[k]++;
				if(a[j][k] == 1) cnt[k]++;
			}
		}
	}
	for(int i = 1; i <= n;i++) cout << res[i] << '\n';
}
void to_thic_cau(){
	cin >> n >> m;
	if(n <= 3000){
		trau();
		return;
	}
	for(int i = 0; i < (1 << m);i++) mn[i] = {inf, inf};
	for(int i = 1; i <= n;i++){
		ll msk = 0;
		for(int j = 0; j < m;j++){
			cin >> a[i][j];
			if(a[i][j] == 1) cnt[j]++, msk |= (1 << j);
		}
		dp[msk]++;
		mp[msk]++;
	}
	for(int i = 0; i < m;i++){
		for(int msk = 0; msk < (1 << m);msk++) if(msk & (1 << i)) dp[msk] += dp[msk ^ (1 << i)];
	}
	for(int msk = 0; msk < (1 << m);msk++){
		ll inv_msk = ((1 << m) - 1) ^ msk;
		for(int sub = msk; sub >= 0;sub = (sub - 1) & msk){
			ll cur = sub | inv_msk;
			ll c = __builtin_popcount(sub);
			ll d = 0;
			for(int final_msk = cur; final_msk >= 0; final_msk = (final_msk - 1) & cur){
				if(((final_msk) & sub) == sub) d += mp[final_msk];
				if(final_msk == 0) break;
			}
			if(d >= 1){
				if(c < mn[msk].F) mn[msk].S = mn[msk].F, mn[msk].F = c;
				else if(c < mn[msk].S) mn[msk].S = c;
			}
			if(d >= 2){
				mn[msk].F = min(mn[msk].F, c); mn[msk].S = min(mn[msk].S, c);
			}
			if(sub == 0) break;
		}
	}
	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";
	}
}

signed main()   
{ 
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll tc = 1;
	//cin >> tc;
	while(tc--) to_thic_cau();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 13 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 13 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 464 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 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 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 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 6 ms 604 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 6 ms 516 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 600 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 13 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 13 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 464 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 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 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 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 6 ms 604 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 6 ms 516 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 600 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 186 ms 856 KB Output is correct
52 Correct 248 ms 600 KB Output is correct
53 Correct 1039 ms 860 KB Output is correct
54 Correct 1044 ms 856 KB Output is correct
55 Correct 53 ms 600 KB Output is correct
56 Correct 865 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 46 ms 26708 KB Output is correct
3 Correct 57 ms 26704 KB Output is correct
4 Correct 38 ms 26192 KB Output is correct
5 Correct 50 ms 26856 KB Output is correct
6 Correct 44 ms 26196 KB Output is correct
7 Correct 51 ms 26704 KB Output is correct
8 Correct 1 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 1 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 47 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 46 ms 26708 KB Output is correct
3 Correct 57 ms 26704 KB Output is correct
4 Correct 38 ms 26192 KB Output is correct
5 Correct 50 ms 26856 KB Output is correct
6 Correct 44 ms 26196 KB Output is correct
7 Correct 51 ms 26704 KB Output is correct
8 Correct 1 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 1 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 47 ms 604 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 163 ms 30292 KB Output is correct
21 Correct 148 ms 30036 KB Output is correct
22 Correct 150 ms 30072 KB Output is correct
23 Correct 138 ms 30532 KB Output is correct
24 Correct 145 ms 30308 KB Output is correct
25 Correct 180 ms 30292 KB Output is correct
26 Correct 195 ms 30364 KB Output is correct
27 Correct 0 ms 348 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 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 6 ms 516 KB Output is correct
37 Correct 1 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 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 6 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 46 ms 26708 KB Output is correct
3 Correct 57 ms 26704 KB Output is correct
4 Correct 38 ms 26192 KB Output is correct
5 Correct 50 ms 26856 KB Output is correct
6 Correct 44 ms 26196 KB Output is correct
7 Correct 51 ms 26704 KB Output is correct
8 Correct 1 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 1 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 47 ms 604 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 163 ms 30292 KB Output is correct
21 Correct 148 ms 30036 KB Output is correct
22 Correct 150 ms 30072 KB Output is correct
23 Correct 138 ms 30532 KB Output is correct
24 Correct 145 ms 30308 KB Output is correct
25 Correct 180 ms 30292 KB Output is correct
26 Correct 195 ms 30364 KB Output is correct
27 Correct 0 ms 348 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 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 6 ms 516 KB Output is correct
37 Correct 1 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 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 6 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Execution timed out 4067 ms 31828 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 46 ms 26708 KB Output is correct
3 Correct 57 ms 26704 KB Output is correct
4 Correct 38 ms 26192 KB Output is correct
5 Correct 50 ms 26856 KB Output is correct
6 Correct 44 ms 26196 KB Output is correct
7 Correct 51 ms 26704 KB Output is correct
8 Correct 1 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 1 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 47 ms 604 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 163 ms 30292 KB Output is correct
21 Correct 148 ms 30036 KB Output is correct
22 Correct 150 ms 30072 KB Output is correct
23 Correct 138 ms 30532 KB Output is correct
24 Correct 145 ms 30308 KB Output is correct
25 Correct 180 ms 30292 KB Output is correct
26 Correct 195 ms 30364 KB Output is correct
27 Correct 0 ms 348 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 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 6 ms 516 KB Output is correct
37 Correct 1 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 344 KB Output is correct
42 Correct 1 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 6 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Execution timed out 4067 ms 31828 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 13 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 13 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 464 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 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 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 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 6 ms 604 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 6 ms 516 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 600 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 186 ms 856 KB Output is correct
52 Correct 248 ms 600 KB Output is correct
53 Correct 1039 ms 860 KB Output is correct
54 Correct 1044 ms 856 KB Output is correct
55 Correct 53 ms 600 KB Output is correct
56 Correct 865 ms 600 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 46 ms 26708 KB Output is correct
59 Correct 57 ms 26704 KB Output is correct
60 Correct 38 ms 26192 KB Output is correct
61 Correct 50 ms 26856 KB Output is correct
62 Correct 44 ms 26196 KB Output is correct
63 Correct 51 ms 26704 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 0 ms 348 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 0 ms 348 KB Output is correct
70 Correct 0 ms 348 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 47 ms 604 KB Output is correct
74 Correct 1 ms 344 KB Output is correct
75 Correct 1 ms 344 KB Output is correct
76 Correct 163 ms 30292 KB Output is correct
77 Correct 148 ms 30036 KB Output is correct
78 Correct 150 ms 30072 KB Output is correct
79 Correct 138 ms 30532 KB Output is correct
80 Correct 145 ms 30308 KB Output is correct
81 Correct 180 ms 30292 KB Output is correct
82 Correct 195 ms 30364 KB Output is correct
83 Correct 0 ms 348 KB Output is correct
84 Correct 0 ms 348 KB Output is correct
85 Correct 0 ms 348 KB Output is correct
86 Correct 0 ms 348 KB Output is correct
87 Correct 1 ms 348 KB Output is correct
88 Correct 0 ms 348 KB Output is correct
89 Correct 1 ms 348 KB Output is correct
90 Correct 0 ms 348 KB Output is correct
91 Correct 1 ms 348 KB Output is correct
92 Correct 6 ms 516 KB Output is correct
93 Correct 1 ms 348 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 1 ms 348 KB Output is correct
97 Correct 1 ms 344 KB Output is correct
98 Correct 1 ms 344 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 1 ms 348 KB Output is correct
101 Correct 6 ms 348 KB Output is correct
102 Correct 1 ms 348 KB Output is correct
103 Execution timed out 4067 ms 31828 KB Time limit exceeded
104 Halted 0 ms 0 KB -