답안 #815549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
815549 2023-08-08T16:51:17 Z happypotato Council (JOI23_council) C++17
컴파일 오류
0 ms 0 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]) {
							// take smaller one
							if (comp(cur, dpb[ncur].ff)) {
								if (comp(cur, dpb[conf].ss)) {
									dpb[conf].ss = cur;
								}
								cur = dpb[ncur].ff;
							} else {
								if (comp(dpb[ncur].ff, dpb[conf].ss)) {
									dpb[conf].ss = 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();
}

Compilation message

council.cpp:1:1: error: 'include' does not name a type
    1 | include <bits/stdc++.h>
      | ^~~~~~~
council.cpp:4:13: error: 'pair' does not name a type
    4 | #define pii pair<int, int>
      |             ^~~~
council.cpp:12:1: note: in expansion of macro 'pii'
   12 | pii dpb[(1 << 20)]; // {which level != 0, which level -1}
      | ^~~
council.cpp: In function 'void PrecompDPB()':
council.cpp:48:4: error: 'dpb' was not declared in this scope; did you mean 'dpf'?
   48 |    dpb[conf] = {conf, conf};
      |    ^~~
      |    dpf
council.cpp:50:4: error: 'dpb' was not declared in this scope; did you mean 'dpf'?
   50 |    dpb[conf] = {conf, -1};
      |    ^~~
      |    dpf
council.cpp:52:4: error: 'dpb' was not declared in this scope; did you mean 'dpf'?
   52 |    dpb[conf] = {-1, -1};
      |    ^~~
      |    dpf
council.cpp:65:10: error: 'dpb' was not declared in this scope; did you mean 'dpf'?
   65 |      if (dpb[ncur].ff != -1) {
      |          ^~~
      |          dpf
council.cpp:89:10: error: 'dpb' was not declared in this scope; did you mean 'dpf'?
   89 |      if (dpb[ncur].ss != -1) {
      |          ^~~
      |          dpf
council.cpp: In function 'void st7()':
council.cpp:135:7: error: 'dpb' was not declared in this scope; did you mean 'dpf'?
  135 |   if (dpb[tar].ff != -1) {
      |       ^~~
      |       dpf
council.cpp:137:12: error: 'max' was not declared in this scope
  137 |     buff = max(buff, m - __builtin_popcount(dpb[tar].ff));
      |            ^~~
council.cpp:140:7: error: 'dpb' was not declared in this scope; did you mean 'dpf'?
  140 |   if (dpb[tar].ss != -1) {
      |       ^~~
      |       dpf
council.cpp:141:11: error: 'max' was not declared in this scope
  141 |    buff = max(buff, m - __builtin_popcount(dpb[tar].ss));
      |           ^~~
council.cpp:145:3: error: 'cout' was not declared in this scope
  145 |   cout << ans << endl;
      |   ^~~~
council.cpp:145:18: error: 'endl' was not declared in this scope
  145 |   cout << ans << endl;
      |                  ^~~~
council.cpp: In function 'void st2()':
council.cpp:172:10: error: 'max' was not declared in this scope
  172 |    ans = max(ans, cur);
      |          ^~~
council.cpp:174:3: error: 'cout' was not declared in this scope
  174 |   cout << ans << endl;
      |   ^~~~
council.cpp:174:18: error: 'endl' was not declared in this scope
  174 |   cout << ans << endl;
      |                  ^~~~
council.cpp: In function 'void solve()':
council.cpp:182:2: error: 'cin' was not declared in this scope
  182 |  cin >> n >> m;
      |  ^~~
council.cpp: At global scope:
council.cpp:201:1: error: 'int32_t' does not name a type
  201 | int32_t main() {
      | ^~~~~~~