Submission #132538

# Submission time Handle Problem Language Result Execution time Memory
132538 2019-07-19T06:52:25 Z 이온조(#3199) Friends (BOI17_friends) C++14
0 / 100
1000 ms 780 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define sz(V) ((int)V.size())

vector<vector<int> > ans;
int N, p, q, P[100009];
vector<int> adj[2509];
bool D[100009], ok[100009];
set<pii> st;

int cnt(int bit) {
	int ret = 0;
	for(int i=0; i<N; i++) if((bit >> i) & 1) {
		for(auto& it: adj[i]) {
			if(((bit >> it) & 1) == 0) ++ret;
		}
	}
	return ret;
}

void Do(int bit) {
	vector<int> S;
	for(int i=0; i<N; i++) if((bit >> i) & 1) S.push_back(i);
	ans.push_back(S);
}

void go(int bit) {
	if(ok[bit]) {
		Do(bit);
		return;
	}
	go(P[bit]);
	go(P[bit] ^ bit);
}

void show(int bit) {
	for(int i=0; i<N; i++) {
		if((bit >> i) & 1) printf("1");
		else printf("0");
	}
	puts("");
}

int main() {
	scanf("%d%d%d",&N,&p,&q);
	assert(N <= 16);
	for(int i=0; i<N; i++) {
		int m; scanf("%d",&m);
		for(int j=0; j<m; j++) {
			int foo; scanf("%d",&foo);
			adj[i].push_back(foo);
			st.insert({i, foo});
		}
	}
	int all = (1<<N) - 1;
	for(int i=1; i<(1<<N); i++) {
		D[i] = ok[i] = (cnt(i) <= q && __builtin_popcount(i) <= p);
		vector<int> S;
		for(int j=0; j<N; j++) if((i >> j) & 1) S.push_back(j);
		for(int k=1; k<(1<<sz(S)); k++) {
			int bit = 0;
			for(int j=0; j<sz(S); j++) if((k >> j) & 1) bit |= (1 << S[j]);
			D[i] |= (D[bit] && D[i ^ bit]);
			if(D[bit] && D[i ^ bit]) P[i] = bit;
			if(D[i]) break;
		}
		// show(i);
		// printf("result: %d\n\n", D[i]);
	}
	for(auto& it: st) if(st.find({it.second, it.first}) == st.end()) D[all] = 0;
	if(D[all]) {
		puts("home");
		go(all);
		printf("%d\n", ans.size());
		for(auto& it: ans) {
			printf("%d ", it.size());
			for(auto& jt: it) printf("%d ", jt);
			puts("");
		}
	}
	else puts("detention");
	return 0;
}

Compilation message

friends.cpp: In function 'int main()':
friends.cpp:75:28: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<std::vector<int> >::size_type {aka long unsigned int}' [-Wformat=]
   printf("%d\n", ans.size());
                  ~~~~~~~~~~^
friends.cpp:77:27: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
    printf("%d ", it.size());
                  ~~~~~~~~~^
friends.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d",&N,&p,&q);
  ~~~~~^~~~~~~~~~~~~~~~~~~
friends.cpp:49:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int m; scanf("%d",&m);
          ~~~~~^~~~~~~~~
friends.cpp:51:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int foo; scanf("%d",&foo);
             ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 372 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 184 ms 592 KB Output is correct
5 Execution timed out 1078 ms 780 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Runtime error 3 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 372 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 184 ms 592 KB Output is correct
5 Execution timed out 1078 ms 780 KB Time limit exceeded
6 Halted 0 ms 0 KB -