답안 #815555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
815555 2023-08-08T16:54:50 Z happypotato Council (JOI23_council) C++17
25 / 100
592 ms 50956 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
// global
int a[300001];
int n, m;
int dpf[(1 << 20)]; // 0: 0, -1: 2+, x: position x
pii dpb[(1 << 20)]; // {which level != 0, which level -1}
bool vis[(1 << 20)];
int ps[300001][20];
void init() {
	// init
 
}
void PrecompDPF() {
	for (int i = 1; i <= n; i++) {
		if (dpf[a[i]] == 0) dpf[a[i]] = i;
		else dpf[a[i]] = -1;
	}
	for (int bit = 0; bit < m; bit++) {
		for (int conf = 0; conf < (1 << m); conf++) {
			if (conf & (1 << bit)) {
				int prev = (conf ^ (1 << bit));
				// cerr << "ADD " << prev << " TO " << conf << endl;
				if (dpf[prev] == -1) {
					dpf[conf] = -1;
				} else if (dpf[prev] != 0) {
					if (dpf[conf] == 0) {
						dpf[conf] = dpf[prev];
					} else {
						dpf[conf] = -1;
					}
				}
			}
		}
	}
}
bool comp(int &lhs, int &rhs) {
	return __builtin_popcount(lhs) < __builtin_popcount(rhs);
}
void PrecompDPB() {
	for (int conf = 0; conf < (1 << m); conf++) {
		if (dpf[conf] == -1) {
			dpb[conf] = {conf, conf};
		} else if (dpf[conf] != 0) {
			dpb[conf] = {conf, -1};
		} else {
			dpb[conf] = {-1, -1};
		}
		vis[conf] = false;
		// cerr << conf << ' ' << dpb[conf].ff << ' ' << dpb[conf].ss << endl;
	}
	for (int bits = m - 1; bits >= 0; bits--) {
		for (int conf = 0; conf < (1 << m); conf++) {
			if (__builtin_popcount(conf) != bits) continue;
			int ncur;
			int cur = 0;
			for (int i = 0; i < m; i++) {
				if (!bool(conf & (1 << i))) {
					ncur = (conf ^ (1 << i));
					if (dpb[ncur].ff != -1) {
						if (comp(dpb[ncur].ff, dpb[conf].ff)) {
							dpb[conf].ff = dpb[ncur].ff;
						}
						if (dpf[dpb[ncur].ff] == -1) {
							if (comp(dpb[ncur].ff, dpb[conf].ss)) {
								dpb[conf].ss = dpb[ncur].ff;
							}
						} else if (cur == 0) {
							cur = dpb[ncur].ff;
						} else if (dpf[cur] != dpf[dpb[ncur].ff]) {
							if (dpf[conf] == 0) {
								// take larger one
								if (comp(cur, dpb[ncur].ff)) {
									if (comp(dpb[ncur].ff, dpb[conf].ss)) {
										dpb[conf].ss = dpb[ncur].ff;
									}
								} else {
									if (comp(cur, dpb[conf].ss)) {
										dpb[conf].ss = cur;
									}
									cur = dpb[ncur].ff;
								}
							} else {
								// take smaller one
								if (comp(cur, dpb[ncur].ff)) {
									if (comp(cur, dpb[conf].ss)) {
										dpb[conf].ss = cur;
									}
								} else {
									if (comp(dpb[ncur].ff, dpb[conf].ss)) {
										dpb[conf].ss = dpb[ncur].ff;
									}
									cur = dpb[ncur].ff;
								}
							}
						}
					}
					if (dpb[ncur].ss != -1) {
						if (comp(dpb[ncur].ss, dpb[conf].ss)) {
							dpb[conf].ss = dpb[ncur].ss;
						}
				// 		if (comp(dpb[ncur].ss, dpb[conf].ff)) {
				// 			dpb[conf].ff = dpb[ncur].ss;
				// 		}
					}
				}
			}
		}
	}
}
void PrecompPS() {
	for (int j = 0; j < m; j++) {
		ps[0][j] = 0;
		for (int i = 1; i <= n; i++) {
			ps[i][j] = ps[i - 1][j] + bool(a[i] & (1 << j));
		}
	}
}
void st7() {
	PrecompDPF();
	// cerr << "DPF:\n";
	// for (int i = 0; i < (1 << m); i++) cerr << dpf[i] << ' '; cerr << endl;
	// cerr << "END\n";
	PrecompDPB();
	// cerr << "DPB:\n";
	// for (int i = 0; i < (1 << m); i++) {
	// 	cerr << i << ": " << dpb[i].ff << ' ' << dpb[i].ss << endl;
	// }
	// cerr << "END\n";
	PrecompPS();
	for (int i = 1; i <= n; i++) {
		int ans = 0, tar = 0;
		for (int j = 0; j < m; j++) {
			if ((ps[n][j] - bool(a[i] & (1 << j))) > (n >> 1)) {
				ans++;
			} else if ((ps[n][j] - bool(a[i] & (1 << j))) == (n >> 1)) {
				tar |= (1 << j);
			}
		}
		tar ^= ((1 << m) - 1);
		// cerr << ans << ' ' << tar << endl;
		// cerr << dpb[tar].ff << ' ' << dpb[tar].ss << endl;
		int buff = 0;
		if (dpb[tar].ff != -1) {
			if (dpf[dpb[tar].ff] != i) {
				buff = max(buff, m - __builtin_popcount(dpb[tar].ff));
			}
		}
		if (dpb[tar].ss != -1) {
			buff = max(buff, m - __builtin_popcount(dpb[tar].ss));
		}
		// cerr << ans << ' ' << buff << endl;
		ans += buff;
		cout << ans << endl;
	}
}
void st6() {
	return st7();
}
void st5() {
	return st7();
}
void st4() {
	return st7();
}
void st3() {
	return st7();
}
void st2() {
	return st7();
	PrecompPS();
	for (int i = 1; i <= n; i++) {
		int ans = 0;
		int cur;
		for (int j = 1; j <= n; j++) {
			if (i == j) continue;
			cur = 0;
			for (int k = 0; k < m; k++) {
				cur += ((ps[n][k] - bool(a[i] & (1 << k)) - bool(a[j] & (1 << k))) >= (n >> 1));
			}
			ans = max(ans, cur);
		}
		cout << ans << endl;
	}
}
void st1() {
	return st2();
}
void solve() {
	// solve
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		a[i] = 0;
		bool temp;
		for (int j = 0; j < m; j++) {
			cin >> temp;
			if (temp) {
				a[i] |= (1 << j);
			}
		}
	}
	if (n <= 300) return st1();
	if (n <= 3000) return st2();
	if (m <= 2) return st3();
	if (m <= 10) return st4();
	if (m <= 14) return st5();
	if (m <= 17) return st6();
	return st7();
}
int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);
	init(); solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 265 ms 21768 KB Output is correct
6 Correct 274 ms 17812 KB Output is correct
7 Correct 304 ms 20520 KB Output is correct
8 Correct 342 ms 20908 KB Output is correct
9 Correct 457 ms 25556 KB Output is correct
10 Correct 396 ms 19864 KB Output is correct
11 Correct 353 ms 22136 KB Output is correct
12 Correct 418 ms 25584 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 4 ms 596 KB Output is correct
42 Correct 5 ms 596 KB Output is correct
43 Correct 5 ms 756 KB Output is correct
44 Incorrect 5 ms 596 KB Output isn't correct
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 265 ms 21768 KB Output is correct
6 Correct 274 ms 17812 KB Output is correct
7 Correct 304 ms 20520 KB Output is correct
8 Correct 342 ms 20908 KB Output is correct
9 Correct 457 ms 25556 KB Output is correct
10 Correct 396 ms 19864 KB Output is correct
11 Correct 353 ms 22136 KB Output is correct
12 Correct 418 ms 25584 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 4 ms 596 KB Output is correct
42 Correct 5 ms 596 KB Output is correct
43 Correct 5 ms 756 KB Output is correct
44 Incorrect 5 ms 596 KB Output isn't correct
45 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 421 ms 50224 KB Output is correct
3 Correct 369 ms 50224 KB Output is correct
4 Correct 403 ms 50160 KB Output is correct
5 Correct 419 ms 50164 KB Output is correct
6 Correct 338 ms 50260 KB Output is correct
7 Correct 364 ms 50120 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 4 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 421 ms 50224 KB Output is correct
3 Correct 369 ms 50224 KB Output is correct
4 Correct 403 ms 50160 KB Output is correct
5 Correct 419 ms 50164 KB Output is correct
6 Correct 338 ms 50260 KB Output is correct
7 Correct 364 ms 50120 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 4 ms 856 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 380 KB Output is correct
20 Correct 551 ms 50256 KB Output is correct
21 Correct 514 ms 50228 KB Output is correct
22 Correct 488 ms 50196 KB Output is correct
23 Correct 535 ms 50516 KB Output is correct
24 Correct 453 ms 50168 KB Output is correct
25 Correct 507 ms 50228 KB Output is correct
26 Correct 517 ms 50200 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 421 ms 50224 KB Output is correct
3 Correct 369 ms 50224 KB Output is correct
4 Correct 403 ms 50160 KB Output is correct
5 Correct 419 ms 50164 KB Output is correct
6 Correct 338 ms 50260 KB Output is correct
7 Correct 364 ms 50120 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 4 ms 856 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 380 KB Output is correct
20 Correct 551 ms 50256 KB Output is correct
21 Correct 514 ms 50228 KB Output is correct
22 Correct 488 ms 50196 KB Output is correct
23 Correct 535 ms 50516 KB Output is correct
24 Correct 453 ms 50168 KB Output is correct
25 Correct 507 ms 50228 KB Output is correct
26 Correct 517 ms 50200 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 416 KB Output is correct
47 Correct 548 ms 50640 KB Output is correct
48 Correct 546 ms 50400 KB Output is correct
49 Correct 545 ms 50492 KB Output is correct
50 Correct 547 ms 50752 KB Output is correct
51 Correct 537 ms 50632 KB Output is correct
52 Correct 592 ms 50624 KB Output is correct
53 Correct 572 ms 50956 KB Output is correct
54 Correct 4 ms 596 KB Output is correct
55 Correct 4 ms 596 KB Output is correct
56 Correct 4 ms 724 KB Output is correct
57 Incorrect 4 ms 604 KB Output isn't correct
58 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 421 ms 50224 KB Output is correct
3 Correct 369 ms 50224 KB Output is correct
4 Correct 403 ms 50160 KB Output is correct
5 Correct 419 ms 50164 KB Output is correct
6 Correct 338 ms 50260 KB Output is correct
7 Correct 364 ms 50120 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 4 ms 856 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 380 KB Output is correct
20 Correct 551 ms 50256 KB Output is correct
21 Correct 514 ms 50228 KB Output is correct
22 Correct 488 ms 50196 KB Output is correct
23 Correct 535 ms 50516 KB Output is correct
24 Correct 453 ms 50168 KB Output is correct
25 Correct 507 ms 50228 KB Output is correct
26 Correct 517 ms 50200 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 0 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 0 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 416 KB Output is correct
47 Correct 548 ms 50640 KB Output is correct
48 Correct 546 ms 50400 KB Output is correct
49 Correct 545 ms 50492 KB Output is correct
50 Correct 547 ms 50752 KB Output is correct
51 Correct 537 ms 50632 KB Output is correct
52 Correct 592 ms 50624 KB Output is correct
53 Correct 572 ms 50956 KB Output is correct
54 Correct 4 ms 596 KB Output is correct
55 Correct 4 ms 596 KB Output is correct
56 Correct 4 ms 724 KB Output is correct
57 Incorrect 4 ms 604 KB Output isn't correct
58 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 265 ms 21768 KB Output is correct
6 Correct 274 ms 17812 KB Output is correct
7 Correct 304 ms 20520 KB Output is correct
8 Correct 342 ms 20908 KB Output is correct
9 Correct 457 ms 25556 KB Output is correct
10 Correct 396 ms 19864 KB Output is correct
11 Correct 353 ms 22136 KB Output is correct
12 Correct 418 ms 25584 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 4 ms 596 KB Output is correct
42 Correct 5 ms 596 KB Output is correct
43 Correct 5 ms 756 KB Output is correct
44 Incorrect 5 ms 596 KB Output isn't correct
45 Halted 0 ms 0 KB -