답안 #667131

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667131 2022-11-30T12:23:04 Z flappybird Political Development (BOI17_politicaldevelopment) C++17
23 / 100
1478 ms 40016 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;
			}
		}
		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 9684 KB Output is correct
3 Correct 10 ms 10548 KB Output is correct
4 Runtime error 1478 ms 24572 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 10 ms 10548 KB Output is correct
4 Runtime error 1478 ms 24572 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9812 KB Output is correct
2 Correct 5 ms 9768 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 5 ms 9684 KB Output is correct
5 Correct 6 ms 9728 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9684 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 5 ms 9812 KB Output is correct
11 Correct 689 ms 40016 KB Output is correct
12 Correct 5 ms 9684 KB Output is correct
13 Correct 697 ms 39836 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 703 ms 39788 KB Output is correct
16 Correct 721 ms 39972 KB Output is correct
17 Correct 730 ms 39748 KB Output is correct
18 Correct 713 ms 39960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 10 ms 10548 KB Output is correct
4 Runtime error 1478 ms 24572 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 10 ms 10548 KB Output is correct
4 Runtime error 1478 ms 24572 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -