답안 #667132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667132 2022-11-30T12:24:08 Z flappybird Political Development (BOI17_politicaldevelopment) C++17
23 / 100
1537 ms 39888 KB
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 201010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MK 11
vector<int> adj[MAX], add[MAX];
int deg[MAX];
int ord[MAX];
int mp[MK][MK];
int dp[1 << MK];
int bcnt[1 << MK];
int ans = 1;
int valid[MK];
int vis[MAX];
set<pii> alledge;
bool ison[MAX];
void calc(int N) {
	if (!N) return;
	ans = max(ans, 2);
	dp[0] = 1;
	dp[1] = 1;
	int i, j;
	for (i = 1; i < N; i++) {
		int mask = 0;
		for (j = i - 1; j >= 0; j--) {
			mask <<= 1;
			if (mp[i][j]) mask |= 1;
		}
		for (j = 0; j < (1 << i); j++) {
			if (dp[j] && (mask & j) == j) dp[1 << i | j] = 1, ans = max(ans, bcnt[1 << i | j] + 1);
			else dp[1 << i | j] = 0;
		}
	}
}
bool chk(int a, int b) {
	if (alledge.find(pii(a, b)) != alledge.end()) return true;
	if (alledge.find(pii(b, a)) != alledge.end()) return true;
	else return false;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int N, K;
	cin >> N >> K;
	int i, j, k, a;
	for (i = 0; i < (1 << MK); i++) {
		a = i;
		while (a) {
			bcnt[i] += a & 1;
			a >>= 1;
		}
	}
	queue<int> q;
	for (i = 0; i < N; i++) {
		cin >> deg[i];
		for (j = 0; j < deg[i]; j++) cin >> a, adj[i].push_back(a), alledge.emplace(a, i);
		if (deg[i] <= K) q.push(i);
	}
	int cnt = 0;
	while (q.size()) {
		int t = q.front();
		q.pop();
		if (vis[t]) continue;
		vis[t] = 1;
		ord[cnt++] = t;
		for (auto v : adj[t]) {
			deg[v]--;
			if (!vis[v] && deg[v] <= K) q.push(v);
		}
	}
	assert(cnt == N);
	for (i = 0; i < N; i++) {
		int v = ord[i];
		ison[v] = true;
		for (auto x : adj[v]) if (ison[x]) add[x].push_back(v), add[v].push_back(x);
		for (j = 0; j < add[v].size(); j++) {
			for (k = j + 1; k < add[v].size(); k++) {
				if (chk(add[v][j], add[v][k])) mp[j][k] = mp[k][j] = 1;
				else mp[j][k] = mp[k][j] = 0;
			}
		}
		assert(add[v].size()<=12);
		calc(add[v].size());
	}
	cout << ans << ln;
}

Compilation message

politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:87:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |   for (j = 0; j < add[v].size(); j++) {
      |               ~~^~~~~~~~~~~~~~~
politicaldevelopment.cpp:88:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |    for (k = j + 1; k < add[v].size(); k++) {
      |                    ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9796 KB Output is correct
3 Correct 10 ms 10656 KB Output is correct
4 Runtime error 1537 ms 21892 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9796 KB Output is correct
3 Correct 10 ms 10656 KB Output is correct
4 Runtime error 1537 ms 21892 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9684 KB Output is correct
5 Correct 6 ms 9788 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 7 ms 9728 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 6 ms 9684 KB Output is correct
11 Correct 749 ms 39848 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 753 ms 39804 KB Output is correct
14 Correct 6 ms 9684 KB Output is correct
15 Correct 736 ms 39784 KB Output is correct
16 Correct 753 ms 39872 KB Output is correct
17 Correct 732 ms 39888 KB Output is correct
18 Correct 731 ms 39824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9796 KB Output is correct
3 Correct 10 ms 10656 KB Output is correct
4 Runtime error 1537 ms 21892 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9796 KB Output is correct
3 Correct 10 ms 10656 KB Output is correct
4 Runtime error 1537 ms 21892 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -