Submission #667130

# Submission time Handle Problem Language Result Execution time Memory
667130 2022-11-30T12:21:54 Z flappybird Political Development (BOI17_politicaldevelopment) C++17
23 / 100
1510 ms 40052 KB
#include <bits/stdc++.h>
#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);
		}
	}
	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:85:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   for (j = 0; j < add[v].size(); j++) {
      |               ~~^~~~~~~~~~~~~~~
politicaldevelopment.cpp:86:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   86 |    for (k = j + 1; k < add[v].size(); k++) {
      |                    ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9776 KB Output is correct
3 Correct 10 ms 10680 KB Output is correct
4 Runtime error 1510 ms 24632 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9776 KB Output is correct
3 Correct 10 ms 10680 KB Output is correct
4 Runtime error 1510 ms 24632 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 5 ms 9724 KB Output is correct
5 Correct 8 ms 9776 KB Output is correct
6 Correct 7 ms 9780 KB Output is correct
7 Correct 6 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 9684 KB Output is correct
11 Correct 741 ms 39908 KB Output is correct
12 Correct 7 ms 9684 KB Output is correct
13 Correct 811 ms 40012 KB Output is correct
14 Correct 5 ms 9684 KB Output is correct
15 Correct 725 ms 40052 KB Output is correct
16 Correct 734 ms 40040 KB Output is correct
17 Correct 725 ms 40012 KB Output is correct
18 Correct 757 ms 40004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9776 KB Output is correct
3 Correct 10 ms 10680 KB Output is correct
4 Runtime error 1510 ms 24632 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9776 KB Output is correct
3 Correct 10 ms 10680 KB Output is correct
4 Runtime error 1510 ms 24632 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -